System Properties for an Application in Apache Tomcat

I need to specify different log4j.configuration properties for different web applications deployed on the same Tomcat instance.

Is it possible to specify system properties for each application in Tomcat?

+4
source share
1 answer

You ask two separate questions (well, at least with Tomcat 7 you ask two separate questions).

Log4j2 is a web application, so it can be configured differently in each web application.

And although you cannot have different system properties for each web application (because the nature of the system means global), you can have different properties available to the programmer for the web application, not system properties.

With Tomcat 7 configured to comply with the Servlet 3.0 specification, you can create your own ServletContainerInitializer, configure the initializer, which must be initialized first, before all other initializers, and then inside this initializer you can read the settings from a file, DB, or something else and β€œpark” them in the ServletContext attribute collection. Typically, your initializer checks the running system and sets the attributes depending on what it detects. There is little point in reading them from a file, since you can simply park them in web.xml. Then, the code in your web application can infer settings from a unique instance of the web application from its ServletContext attribute collection. This allows you to configure each web application or each instance of the same web application.

+1
source

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


All Articles