title: Spring cloud config /refresh crashes when spring.main.sources is set
body: <p>Spent all day tracking this down...</p>
  
  <p>Using spring-boot 1.3.0.RELEASE and spring-cloud-starter-config 1.1.0.M3</p>
  
  <p>When I set the main class with in the application.properties file with this:</p>
  
  <pre><code>spring.main.sources=com.myapp.MyApplication
  </code></pre>
  
  <p>I start the app and i send a post request to <a href="http://localhost:8080/refresh" rel="nofollow">http://localhost:8080/refresh</a> i get the following error:</p>
  
  <pre><code>org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.cloud.context.environment.EnvironmentManager@76d00da2] with key 'environmentManager'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager
      at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:550) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:432) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:129) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:78) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:58) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) [spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) [spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119) [spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
      at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:325) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.cloud.endpoint.RefreshEndpoint.addConfigFilesToEnvironment(RefreshEndpoint.java:86) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.cloud.endpoint.RefreshEndpoint.refresh(RefreshEndpoint.java:73) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.cloud.endpoint.RefreshEndpoint.invoke(RefreshEndpoint.java:140) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.cloud.endpoint.RefreshEndpoint.invoke(RefreshEndpoint.java:48) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at org.springframework.boot.actuate.endpoint.mvc.AbstractEndpointMvcAdapter.invoke(AbstractEndpointMvcAdapter.java:53) [spring-boot-actuator-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke(EndpointMvcAdapter.java:45) [spring-boot-actuator-1.3.1.RELEASE.jar:1.3.1.RELEASE]
      at org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke(GenericPostableMvcEndpoint.java:50) [spring-cloud-context-1.1.0.M3.jar:1.1.0.M3]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
      at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
  </code></pre>
  
  <p>If i comment out spring.main.sources in the application.properties file and restart the application posting to the /refresh method works without errors.  </p>
  
  <p>Is this a bug?</p>
  
  <p>Here is a sample project:</p>
  
  <p><a href="https://github.com/jmandawg/spring-cloud-config-bug.git" rel="nofollow">https://github.com/jmandawg/spring-cloud-config-bug.git</a></p>
  
  <p>Run the spring-boot app and Send a post request to <a href="http://localhost:8080/refresh" rel="nofollow">http://localhost:8080/refresh</a> and watch it crash.  </p>
  
  <p>Comment out the one line in application.properties restart the app and send a post request to /refresh and all is well.</p>