Where to store constants with Java-Servlets

时间:2016-07-11 21:33:52

标签: java tomcat servlets

I have a Webservice written with Java Servlets. Now there are two files which use a constant and this constant needs to be set different depending on which computer the webservice is installed.

So I need it to be stored in a file which can be accessed also if the project is already deployed to Tomcat.

Does anyone know where do I store something like that and how to read the constant in the Servlets?

Thanks!

1 个答案:

答案 0 :(得分:0)

I've had success with creating a property file for each host. Then you lookup the hostname, and retrieve the appropriate property file.

You can then commit configuration to source control, to make ci and test environments easier to configure.

This approach works for known fixed servers, however if your looking at a docker deployment, you can use an environment variable to pass in the name of the property file to use.