Reputation: 280181
My web application performs some of its behavior by reading from a properties file. I want to have an admin console that can modify the properties file(s) while the application is running through a jsp interface. I can currently read the properties file by doing the following:
Properties props = new Properties();
props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(FILE_PATH));
I can then pass those to my view and display them.
When I want to modify them though, I'm not able to find the properties file the same way (need an outputstream) to save the new property values, unless I pass a full path to the file.
I've read around that it's bad practice to modify a resource given to you by the ClassLoader. If I was to put the properties file external to the web application, how can I make sure it is locked while the modification are being done? Is there another way to do this (properties have to be in a .properties file).
I'm on Tomcat with Spring MVC if that makes any difference.
Upvotes: 2
Views: 1267
Reputation: 80633
I would keep your current properties file exactly where it is, and use those as the base 'loading' source. All overrides would go to a location external to the web app (make the location configurable). Your startup logic would always be:
Quite obviously, whenever a property is changed via the admin console it will be saved as an override. A nice feature of this setup, apart from solving the application archive issue, is that you can then provide the users an option to restore a property value to its 'default'.
Upvotes: 1