2014-12-16 1 views
0

우리는 우리의 응용 프로그램을 위해 스프링 부트를 사용하고 있습니다. 응용 프로그램을 시작한 후 런타임에 기존 Bean을 기존 Applicationcontext에 추가 (로드)합니다.스프링 부트 응용 프로그램에서 Spring ApplicationContext를 새로 고치는 동안 예외 발생

AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(); 
appContext.register(NewBean.class); 
appContext.refresh(); 

우리가 MBean가 일부 엔드 포인트를 다시 등록하려고하는 새로 고침 동안

의 ApplicationContext

의 새로 고침을하고 우리는 모든 엔드 포인트에 대해 다음과 같은 오류 (점점 오류가 발생하는 빈을 추가 한 후 - requestMappingEndpoint , environmentEndpoint, healthEndpoint, beansEndpoint, infoEndpoint, metricsEndpoint, traceEndpoint, dumpEndpoint, autoConfigurationAuditEndpoint, shutdownEndpoint, configurationPropertiesReportEndpoint)

Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Endpoint,name=configurationPropertiesReportEndpoint 
     at com.sun.jmx.mbeanserver.Repository.addMBean(Unknown Source) 
     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(Unknown Source) 
     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(Unknown Source) 
     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(Unknown Source) 
     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source) 
     at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source) 
     at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195) 
     at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:662) 
     at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:605) 

아무도이 예외를 건너 뛰는 방법을 알려줄 수 있습니까?

나는 너무

@EnableIntegrationMBeanExport(registration = RegistrationPolicy.REPLACE_EXISTING) 

을 다음하지만 당신이 기존ApplicationContext에 새로 고침을 요청하기 전에 아래의 예외를

Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [o[email protected]16c5464] with key 'integrationMbeanExporter'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.integration.monitor:name=integrationMbeanExporter,type=IntegrationMBeanExporter 
    at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:609) 
    at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:534) 
    at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBeanExporter.java:416) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) 
    ... 22 more 
Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.integration.monitor:name=integrationMbeanExporter,type=IntegrationMBeanExporter 
    at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) 
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) 
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) 
    at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195) 
    at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:662) 
    at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:599) 
    ... 26 more 
+2

먼저 다른 빈을 계속 실행하여 삭제해야합니다. 빈을 추가하여 런타임을 추가해야하는 이유는 무엇입니까? 여기서 보여주는 것은 새로운 컨텍스트를 구성하고 있으므로 어떤 일이 발생해야하는지 확신 할 수 없다는 것입니다. 'register' 메소드는 임의의 bean이 아닌 설정 클래스를위한 것이기도합니다. 만약 그것들을 추가하려면'registerSingleton'처럼'ApplicationContext'에 메소드 중 하나를 사용하십시오. 하지만 일반적으로 런타임에 콩을 추가하는 것은 나쁜 일이되어야합니다 (imho). –

+0

@ M.Deinum 이것은 설명이 아닌 대답으로 간주됩니다. –

답변

0

을 받고 시도, 당신은 먼저 다른 콩이 실행 계속 파괴한다.

AnnotationConfigApplicationContext appContext = new AnnotationConfigApplicationContext(); 
appContext.register(NewBean.class); 
appContext.refresh(); 

은 당신이 여기에 표시하는 것은 당신이 새로운 컨텍스트를 구성하는 대신 기존의 것을 재사용하는 것입니다. register 메서드는 임의의 콩이 아닌 @Configuration 클래스에도 사용됩니다. 추가하려는 경우 ApplicationContext에있는 방법 중 하나를 사용하십시오 (예 : registerSingleton). 하지만 일반적으로 런타임에 콩을 추가하는 것은 나쁜 일이되어야합니다 (imho).

0

일부 applicationContext는 시간을 새로 고칠 수 있지만 AnnotationConfigApplicationContext는 새로 고칠 수 없습니다. 새로 고침 메서드를 실행 한 AnnotationConfigApplicationContext를 구성 할 때 예외가보고되어 먼저 파기하고 새로 고침 할 수 있습니다.

관련 문제