java - Getting exception while refreshing Spring ApplicationContext in Spring Boot application -


we using spring boot our application. after starting application, in runtime adding(loading) new bean existing applicationcontext.

annotationconfigapplicationcontext appcontext = new annotationconfigapplicationcontext(); appcontext.register(newbean.class); appcontext.refresh(); 

after adding bean doing refresh of applicationcontext

during refresh mbean trying reregister endpoints , getting following error (getting error these endpoints - requestmappingendpoint, environmentendpoint, healthendpoint, beansendpoint, infoendpoint, metricsendpoint, traceendpoint, dumpendpoint, autoconfigurationauditendpoint, shutdownendpoint, configurationpropertiesreportendpoint)

caused by: javax.management.instancealreadyexistsexception: org.springframework.boot:type=endpoint,name=configurationpropertiesreportendpoint         @ com.sun.jmx.mbeanserver.repository.addmbean(unknown source)         @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registerwithrepository(unknown source)         @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registerdynamicmbean(unknown source)         @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registerobject(unknown source)         @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registermbean(unknown source)         @ com.sun.jmx.mbeanserver.jmxmbeanserver.registermbean(unknown source)         @ org.springframework.jmx.support.mbeanregistrationsupport.doregister(mbeanregistrationsupport.java:195)         @ org.springframework.jmx.export.mbeanexporter.registerbeaninstance(mbeanexporter.java:662)         @ org.springframework.jmx.export.mbeanexporter.registerbeannameorinstance(mbeanexporter.java:605) 

can please tell how skip exception?

i have tried following too

@enableintegrationmbeanexport(registration = registrationpolicy.replace_existing) 

but getting below exception

caused by: org.springframework.jmx.export.unabletoregistermbeanexception: unable register mbean [org.springframework.integration.monitor.integrationmbeanexporter@16c5464] key 'integrationmbeanexporter'; nested exception javax.management.instancealreadyexistsexception: org.springframework.integration.monitor:name=integrationmbeanexporter,type=integrationmbeanexporter     @ org.springframework.jmx.export.mbeanexporter.registerbeannameorinstance(mbeanexporter.java:609)     @ org.springframework.jmx.export.mbeanexporter.registerbeans(mbeanexporter.java:534)     @ org.springframework.jmx.export.mbeanexporter.afterpropertiesset(mbeanexporter.java:416)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1612)     @ 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     @ com.sun.jmx.mbeanserver.repository.addmbean(repository.java:437)     @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registerwithrepository(defaultmbeanserverinterceptor.java:1898)     @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registerdynamicmbean(defaultmbeanserverinterceptor.java:966)     @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registerobject(defaultmbeanserverinterceptor.java:900)     @ com.sun.jmx.interceptor.defaultmbeanserverinterceptor.registermbean(defaultmbeanserverinterceptor.java:324)     @ com.sun.jmx.mbeanserver.jmxmbeanserver.registermbean(jmxmbeanserver.java:522)     @ org.springframework.jmx.support.mbeanregistrationsupport.doregister(mbeanregistrationsupport.java:195)     @ org.springframework.jmx.export.mbeanexporter.registerbeaninstance(mbeanexporter.java:662)     @ org.springframework.jmx.export.mbeanexporter.registerbeannameorinstance(mbeanexporter.java:599)     ... 26 more 

before call refresh on existing applicationcontext, should first destroy else beans keep running.

annotationconfigapplicationcontext appcontext = new annotationconfigapplicationcontext(); appcontext.register(newbean.class); appcontext.refresh(); 

what show here constructing new context instead of reusing existing one. register method intended @configuration classes not arbitrary beans. if want add use 1 of methods on applicationcontext like, registersingleton. in general adding beans @ runtime should bad thing (imho).


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -