user1489861
user1489861

Reputation: 1

How to detect tomcat context reload

I have a config.properties file to store Credentials and IP address for my application as Key Value pairs. However writes to this properties file reloads the application context in tomcat. I am writing to properties file as below

   URL propUrl=this.getClass().getClassLoader().getResource(PROPERTIES_FILE);
   prop.store(new FileOutputStream(propUrl.getPath()), null);

So,

1.) Is there a way to detect a tomcat context reload in Java.

or

2.) Is there a way to prevent context reload and read the config.properties file

Upvotes: 0

Views: 2832

Answers (2)

matt b
matt b

Reputation: 140011

To disable automatic reloading of the context (which is the Tomcat term for the webapp), set the reloadable attribute of the <Context> element in the server config to false. See here for reference, search for "reloadable".

Upvotes: 0

Suraj Chandran
Suraj Chandran

Reputation: 24801

  1. If the ServletContextListener is not helping. You can try using a LifeCycleListener
  2. Set the property reloadable=false to prevent reloading of the context.

Upvotes: 1

Related Questions