2016-08-30 129 views
2

我在尝试在Linux服务器的tomcat 8中部署Spring集成的代码时收到InstanceAlreadyExistsException,其中包含2个独立的流。我提到了几个论坛,但仍然无法找到解决方案。但是在我的本地tomcat 8在windows平台上进行测试时没有得到这个异常。任何输入赞赏。Spring-Integration UnableToRegisterMBeanException:InstanceAlreadyExistsException

Stacktrace - 
2016-08-30 14:27:40 ERROR SpringApplication:838 - Application startup failed 
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [getCities.channel#0] with key 'org.springframework.integration:type=MessageChannel,name=getCities.channel#0'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.integration:type=MessageChannel,name=getCities.channel#0 
    at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.integration.monitor.IntegrationMBeanExporter.registerChannels(IntegrationMBeanExporter.java:675) ~[spring-integration-jmx-4.3.1.RELEASE.jar:4.3.1.RELEASE] 
    at org.springframework.integration.monitor.IntegrationMBeanExporter.afterSingletonsInstantiated(IntegrationMBeanExporter.java:271) ~[spring-integration-jmx-4.3.1.RELEASE.jar:4.3.1.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:796) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:150) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:130) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE] 
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) [spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5261) [catalina.jar:8.0.35] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [catalina.jar:8.0.35] 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.35] 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.35] 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.35] 
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:940) [catalina.jar:8.0.35] 
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1816) [catalina.jar:8.0.35] 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_91] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_91] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_91] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_91] 
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91] 
Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.integration:type=MessageChannel,name=getCities.channel#0 
    at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) ~[?:1.8.0_91] 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) ~[?:1.8.0_91] 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) ~[?:1.8.0_91] 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) ~[?:1.8.0_91] 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) ~[?:1.8.0_91] 
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) ~[?:1.8.0_91] 
    at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:678) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
    at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:615) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE] 

的配置将被下面 -

@Configuration 
@EnableAutoConfiguration(exclude = JmxAutoConfiguration.class) 
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) 
@EnableAspectJAutoProxy 
@EnableAsync 
@EnableWebMvc 
@ComponentScan(basePackages = "foobar") 
@PropertySource("classpath:environments/dev.properties") 
@Import({SecurityConfig.class, IntegrationConfig.class}) 
public class AppConfig extends WebMvcConfigurerAdapter { 
    @Autowired 
    Environment environment; 

    @Bean 
    @Scope(BeanScopes.SINGLETON) 
    public Logger getLogger() { 
     return LoggerFactory.getLogger("SampleService"); 
    } 

    @Bean 
    public LoggerAspect loggerAspect() { 
     return new LoggerAspect(getLogger(), jsonMapper()); 
    } 
} 

@EnableIntegration 
@IntegrationComponentScan(basePackages = "fooBar") 
@Import({FirstConfig.class, SecondConfig.class}) 
public class IntegrationConfig { 

} 

@MessagingGateway 
public interface FirstGateway { 
    @Gateway(requestChannel = "getCitiesChannel") 
    CityModel[] getCities(Message<FirstPayload> message); 
} 

public class FirstConfig { 
    @Bean 
    public MessageChannel getCitiesChannel() { 
     return MessageChannels.direct().get(); 
    } 

    @Bean 
    public IntegrationFlow sdsGetCities() { 
     return IntegrationFlows 
       .from("input") 
       .channel("getCitiesChannel") 

       .handle(foobar) 
       .get(); 
    } 
} 

@MessagingGateway 
public interface SecondGateway { 
    @Gateway(requestChannel = "getProductDetailsChannel") 
    ProductModel getProductDetails(Message<SecondPayload> message); 
} 

public class SecondConfig { 
    @Bean 
    public MessageChannel getProductDetailsChannel() { 
     return MessageChannels.direct().get(); 
    } 

    @Bean 
    public IntegrationFlow getProductDetails() { 
     return IntegrationFlows 
       .from("input") 
       .channel("getProductDetailsChannel") 
       .handle(foobar) 
       .get(); 
    } 
} 

回答

1

你不显示您的@EnableIntegrationMBeanExport;如果要部署2个应用类似流,你需要把每一个应用程序在不同的领域@EnableIntegrationMBeanExport(defaultDomain="foo")@EnableIntegrationMBeanExport(defaultDomain="bar"),所以

org.springframework.integration:type=MessageChannel,name=getCities.channel#0 

成为

foo:type=MessageChannel,name=getCities.channel#0 

bar:type=MessageChannel,name=getCities.channel#0 

如果它是只有一个应用程序(它看起来像),那么这意味着以前的部署没有正常关闭。

+0

您是在FirstConfig还是IntegrationConfig上定义了注释? – ydd1987

+0

感谢加里,我有我的AppConfig类,它包含注释(抱歉,我没有先前分享它)。这个类对于这两个集成都很常见。 –

+0

您可以使用属性占位符,例如'defaultDomain =“$ {managed.domain}”'并在每个实例中使用不同的属性值。我们有一个[测试用例可以这样做](https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jmx/src/test/java/org/springframework/integration/jmx /configuration/EnableMBeanExportTests.java#L123)。 –