Spring integration Spring集成无法注册TermBeanException:InstanceAlreadyExistsException

Spring integration Spring集成无法注册TermBeanException:InstanceAlreadyExistsException,spring-integration,Spring Integration,当我试图在linux服务器的Tomcat8中部署带有Spring集成的代码时,我得到了InstanceAlreadyExistsException,它有两个独立的流。我参考了几个论坛,仍然无法找到解决方案。但是我在windows平台上测试本地Tomcat8时没有遇到这个异常。欢迎您的任何意见 Stacktrace - 2016-08-30 14:27:40 ERROR SpringApplication:838 - Application startup failed org.springfr

当我试图在linux服务器的Tomcat8中部署带有Spring集成的代码时,我得到了InstanceAlreadyExistsException,它有两个独立的流。我参考了几个论坛,仍然无法找到解决方案。但是我在windows平台上测试本地Tomcat8时没有遇到这个异常。欢迎您的任何意见

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();
    }
}
@配置
@EnableAutoConfiguration(exclude=JmxAutoConfiguration.class)
@EnableMBeanExport(注册=注册策略。忽略现有)
@促性腺激素
@使能同步
@EnableWebMvc
@组件扫描(basePackages=“foobar”)
@PropertySource(“classpath:environments/dev.properties”)
@导入({SecurityConfig.class,IntegrationConfig.class})
公共类AppConfig扩展WebMVCConfigureAdapter{
@自动连线
环境;
@豆子
@范围(BeanScopes.SINGLETON)
公共记录器getLogger(){
返回LoggerFactory.getLogger(“SampleService”);
}
@豆子
公共日志SPECT日志SPECT(){
返回新的loggerspect(getLogger(),jsonMapper());
}
}
@使能集成
@IntegrationComponentScan(basePackages=“fooBar”)
@导入({FirstConfig.class,SecondConfig.class})
公共类集成配置{
}
@消息网关
公共接口网关{
@网关(requestChannel=“getCitiesChannel”)
CityModel[]获取城市(消息);
}
公共类FirstConfig{
@豆子
公共消息频道getCitiesChannel(){
返回MessageChannels.direct().get();
}
@豆子
公共集成流sdsGetCities(){
返回积分流
.来自(“输入”)
.频道(“getCitiesChannel”)
.handle(foobar)
.get();
}
}
@消息网关
公共接口网关{
@网关(requestChannel=“GetProductDetailsAnnel”)
ProductModel getProductDetails(消息);
}
公共类SecondConfig{
@豆子
public MessageChannel getProductDetailsAnnel(){
返回MessageChannels.direct().get();
}
@豆子
公共集成流getProductDetails(){
返回积分流
.来自(“输入”)
.channel(“getProductDetailsChannel”)
.handle(foobar)
.get();
}
}

您没有显示您的
@EnableIntegrationMBeanExport
;如果要部署具有类似流的两个应用程序,则需要将每个应用程序放在不同的域
@enableigrationmbeanexport(defaultDomain=“foo”)
@enableigrationmbeanexport(defaultDomain=“bar”)
,因此

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

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

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

试试这个

<context:mbean-export registration="replaceExisting"/>

我在使用抽象基类进行集成测试时遇到了这个错误


我将@DirtiesContext添加到我的基类中,以便在每次测试之间刷新应用程序上下文。

您是在FirstConfig还是IntegrationConfig上定义注释?谢谢Gary,我有一个保存注释的AppConfig类(很抱歉,我之前没有共享它)。此类对于两个集成都是通用的。您可以使用属性占位符,例如
defaultDomain=“${managed.domain}”
,并在每个实例中使用不同的属性值。我们有一个好主意。
<context:mbean-export registration="replaceExisting"/>