开发者

Per-application system properties in Apache Tomcat

My current need is to specify different log4j.configuration properties for different web applications deployed on t开发者_如何学运维he same Tomcat instance.

Is it possible in Tomcat to specify system properties on a per-application basis?


You're asking two separate questions (well, at least as of Tomcat 7 you are asking two separate questions).

Log4j2 is web app aware, so it can be configured differently in each web app.

And while you can't have different system properties for each web app (because by its very nature, system means global), you can have different programmer accessible properties per web app, just not system properties.

With Tomcat 7 configured to conform to the Servlet 3.0 specification, you can create your own ServletContainerInitializer, configure that initializer to be initialized first, before all other initializers, and then, within that initializer you can read settings out of a file, DB or anything else and "park" them in the ServletContext's attributes collection. Typically, your initializer would inspect the system it's running on and set the attributes based on what it discovers. There's little point in reading them from a file, since you could simply park them in web.xml. Then code in your web app can pull the settings out of the web app's unique instance of its ServletContext's attribute collection. This allows each web app, or each instance of the same web app, to be uniquely configured.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜