How to switch between the two spring context in runtime?
- by Selector
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?