花了一整天时间跟踪这个...
使用spring-boot 1.3.0.RELEASE和spring-cloud-starter-config 1.1.0.M3
当我在application.properties文件中设置主类时,使用:
spring.main.sources=com.myapp.MyApplication
我启动应用程序,然后向http://localhost:8080/refresh发送帖子请求,我收到以下错误:
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]
如果我在application.properties文件中注释掉spring.main.sources并重新启动应用程序发布到/ refresh方法,则可以正常工作。
这是一个错误吗?
以下是一个示例项目:
https://github.com/jmandawg/spring-cloud-config-bug.git
运行spring-boot应用程序并向http://localhost:8080/refresh发送帖子请求并观察它是否崩溃。
注释掉application.properties中的一行,重启应用程序并向/ refresh发送一个帖子请求,一切顺利。