Is spring application context reloading via ConfigurableApplicationContext refresh() considered bad-practice

StackOverflow https://stackoverflow.com/questions/7980701

Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top