0

I'm using spring mvc and tomcat as a server. I want to be able to change a jndi field that is Autowired(as String):

<jee:jndi-lookup id="someMessage" jndi-name="someMessage"/>

in one of the my services, that is referenced to conf/context.xml of Tomcat, that looks something like this:

<Environment name="someMessage" value="Change this." type="java.lang.String" />. 

However, when I change the value on context.xml, this change is not reflected on my service managed by spring, unless I restart server. Is there anyway to reflect this change without restarting or redeploying war? I know there is a solution to include such a dynamic field in one of properties file and then use commons configuration library to reload the changes, but I'm looking for a solution to keep this field on my conf/context.xml...

Meriton Husaj
  • 239
  • 3
  • 9
  • 1
    Is your context.xml in META-INF in your webapp or at the root of Tomcat? If it's in your webapp, you can set reloadable - see [the context docs](https://tomcat.apache.org/tomcat-8.0-doc/config/context.html) under the "reloadable" field and the exploded WAR will be polled for changes. But, as the docs say, this is pretty expensive. You can also set it at a virtual host level and reload just that virtual host/webapp. – stdunbar Jan 28 '16 at 17:30
  • It's on the root of Tomcat. Reloading it seems an expensive way to do it, even though it's a solution. – Meriton Husaj Jan 28 '16 at 17:50

2 Answers2

0

I think that is not possible. Why don't use a property file or a static class?

Melknix
  • 39
  • 3
  • The guys that take care of servers already know how to work with context.xml and it is "easier" to tell them to change a property in there, then to go for example in conf/webapps/whatever/WEB-INF(or META-INF) and look for a specific properties file to change a value there. It's a sensitive information so I wouldn't want to put it into a static class and work with that (make a call for it or anything). But if there's no other way around, seems like commons configuration and putting it on properties file is the one I'll have to go with. – Meriton Husaj Jan 28 '16 at 17:48
0

As far as I know, it's impossible if you put it into the conf/context.xml of your tomcat home as the following doc shows:

  • StandardContext.html#reload(): If the context.xml has changed, you should stop this Context and create (and start) a new Context instance instead. -- i.e. can't achieve by original context
  • Reload Existing App: Reload an existing web application, to reflect changes in the contents of /WEB-INF/classes or /WEB-INF/lib. -- i.e. not reflect the change of context.xml

But you can define your app's /META-INF/context.xml, which will be packed into war and you can replace war without restart server.

Tony
  • 5,972
  • 2
  • 39
  • 58