Various environment variables for war in tomcat

Is there a way to have different environment variables for different military files in tomcat? I use a third-party war and need several deployments of the same war, but with different environment variables (so it loads different configurations).

+4
source share
2 answers

Easy if you run two instances of Tomcat yourself. I assume that you are talking about OS environment variables.

You can also set properties in Tomcat for each military / web application. This will allow you to launch two wars in one instance of Tomcat. But that is not what you requested.

+1
source

Ok, the complete crazy hack idea:

Deploy PropertyPlayHolderConfigurer (or use Tomcat's web.xml) for each application instance and load properties with the same name as System.properties ().

Then create a delegate property class that contains both sets of properties. Then

Properties props = new DelegatingProperties(app1Props,app2Props) System.setProperties(delegate); public class DelegatingProperties extends Properties { private Properties app1Props; private Properties app2Props; public DelegatingProperties(Properties app1Props, Properties app2Props) { this.app1Props = app1Props; this.app2Props = app2Props; } public String getProperty(String prop) { // begin crazy science String caller = new Throwable().getStackTrace()[0].getClassName(); // this is where you get creative. // Do the System.setProperties() above so you can intercept calls to //getProperty() // and find out the FQCN of the library class(es) that need these variable // (use your debugger). // then implement the logic here to decide which of the 2 property sets you have // you will query to get the correct results } } 

These are the SYSTEM properties that we are talking about, and they are intended for use in the system. Your library was probably developed when it was 1-app-1-jvm (or the developer is also a smell).

Can I get a props for creativity? :)

+1
source

Source: https://habr.com/ru/post/1273934/


All Articles