How to switch between the two spring context in runtime?

Posted by Selector on Stack Overflow See other posts from Stack Overflow or by Selector
Published on 2012-06-25T09:13:00Z Indexed on 2012/06/25 9:15 UTC
Read the original article Hit count: 167

Filed under:
|
|
|
|

I have current ApplicationContext and I want to replace it by newAppContext

ApplicationContext currentAppContext = getOldAppContext  ();
ApplicationContext newAppContext = loadAppContext ();

If i do:

currentAppContext.stop();
currentAppContext.close();
currentAppContext= newAppContext;

And then try:

currentAppContext.getBean("SampleBean");

I have follow error:

java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

How to substitute spring context?

© Stack Overflow or respective owner

Related posts about java

Related posts about spring