解决spring-cloud应用无法部署在同一个容器中的问题

I have two services which are eureka clients (using @EnableDiscoveryClient). Both services are packaged in separate war files. At the time of deployment (single tomcat container), one service gets deployed but during the deployment of second service, below error is thrown

同样遇到了网上人遇到的这个问题在使用eureka clients(@EnableDiscoveryClient)的时候两个war无法在tomcat容器里部署,发生下边的错误

org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.cloud.context.environment.EnvironmentManager@5028d59b] 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) ~[MBeanExporter.class:4.2.4.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:550) ~[MBeanExporter.class:4.2.4.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:432) ~[MBeanExporter.class:4.2.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792) ~[DefaultListableBeanFactory.class:4.2.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[AbstractApplicationContext.class:4.2.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[AbstractApplicationContext.class:4.2.4.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[EmbeddedWebApplicationContext.class:1.3.2.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[SpringApplication.class:1.3.2.RELEASE]
        at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[SpringApplication.class:1.3.2.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[SpringApplication.class:1.3.2.RELEASE]
        at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) [SpringBootServletInitializer.class:1.3.2.RELEASE]
        at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) [SpringBootServletInitializer.class:1.3.2.RELEASE]
        at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) [SpringBootServletInitializer.class:1.3.2.RELEASE]
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [SpringServletContainerInitializer.class:4.2.4.RELEASE]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5210) [catalina.jar:8.0.14]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.14]
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) [catalina.jar:8.0.14]
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) [catalina.jar:8.0.14]
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) [catalina.jar:8.0.14]
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1071) [catalina.jar:8.0.14]
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1721) [catalina.jar:8.0.14]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_74]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_74]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_74]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_74]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_74]
Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager
        at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) ~[na:1.8.0_74]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) ~[na:1.8.0_74]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) ~[na:1.8.0_74]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) ~[na:1.8.0_74]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) ~[na:1.8.0_74]
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) ~[na:1.8.0_74]
        at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195) ~[MBeanRegistrationSupport.class:4.2.4.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:678) ~[MBeanExporter.class:4.2.4.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:615) ~[MBeanExporter.class:4.2.4.RELEASE]
        ... 25 common frames omitted


只需要增加一项配置 spring.jmx.default-domain给不同的application即可。

参考链接为:https://stackoverflow.com/questions/28197414/spring-cloud-error-deploying-two-eureka-clients-in-one-container


你可能感兴趣的:(微服务)