Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 257
Jeremy S. Avatar asked Mar 27 '26 09:03

Jeremy S.


1 Answers

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.

like image 174
pap Avatar answered Mar 28 '26 22:03

pap