3

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?

Jeremy S.
  • 6,423
  • 13
  • 48
  • 67

1 Answers1

5

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.

pap
  • 27,064
  • 6
  • 41
  • 46
  • Thanks for the heads up about proxy classes and PermGen, the InitalizingBean is not used in our app for now so it doesn't affect me, besides that I found a [discussion](http://stackoverflow.com/questions/1124131/what-can-be-done-with-permgen-out-of-space-exception-in-tomcat-spring-hibernat) about **PermGen, Spring and Hibernate**, seems like pretty a big issue – Jeremy S. Nov 02 '11 at 13:37