首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring集成UnableToRegisterMBeanException: Spring

Spring集成UnableToRegisterMBeanException: Spring
EN

Stack Overflow用户
提问于 2016-08-30 22:42:18
回答 3查看 3.6K关注 0票数 2

在尝试将Spring Integration的代码部署到linux服务器的Tomcat8中时,我得到了InstanceAlreadyExistsException,它有两个独立的流。我参考了几个论坛,但仍然无法找到解决方案。但是当我在windows平台上测试我本地的tomcat8时,我没有得到这个异常。任何意见都是值得感谢的。

代码语言:javascript
复制
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]

配置如下所示:

代码语言:javascript
复制
@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();
    }
}
EN

回答 3

Stack Overflow用户

发布于 2016-08-30 23:00:04

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

代码语言:javascript
复制
org.springframework.integration:type=MessageChannel,name=getCities.channel#0

变成了

代码语言:javascript
复制
foo:type=MessageChannel,name=getCities.channel#0

代码语言:javascript
复制
bar:type=MessageChannel,name=getCities.channel#0

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

票数 1
EN

Stack Overflow用户

发布于 2019-12-02 10:55:41

尝尝这个

代码语言:javascript
复制
<context:mbean-export registration="replaceExisting"/>
票数 0
EN

Stack Overflow用户

发布于 2020-03-02 01:38:39

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39230584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档