We have a Spring application that is hosted on a shared tomcat instance.
Sometimes we have to reload the spring application context but don't want to restart the Tomcat server, because other application's are hosted there as well.
Is refreshing springs application context via
((ConfigurableApplicationContext)applicationContext).refresh();
considered bad practice?
What alternatives do I have?
A few issues that might arise -
Firstly, refresh() should destroy all beans currently living in the context (singletons etc) and recreate them, so any bootstrapping that might happen will happen again (stuff you put in InitializingBean
beans etc). This is more of an issue for you, to make sure that all initializing code you've written is safe to be executed again.
Another thing to keep an eye on is how a refresh will affect the permanent memory generation (permgen). Since spring can (and will) proxy classes and create on-the-fly runtime-classes, this may prove to be a resource-leak since the bean-factory will probably create new runtime-classes when it refreshed the context.
来源:https://stackoverflow.com/questions/7980701/is-spring-application-context-reloading-via-configurableapplicationcontext-refre