java - Tomcat的上下文层次结构

标签 java tomcat servlets

我知道 tomcat 可以通过几种不同的方式定义上下文。对于这个特定问题,我在 $CATALINA_HOME/conf/context.xml 中定义了一个主上下文,并在每个相应模块的 /META-INF/context.xml 中定义了每个模块上下文嗯>。我的问题是,如果我在主上下文中设置了某些未在每个模块上下文中设置/覆盖的参数,那么这些参数在加载每个模块上下文时是否仍然有效。

示例:

|----$CATALINA_HOME/conf/context.xml (i have logAbandoned=true set here)
|
|----webaps
       |
       |---META-INF/context.xml (no mention of logAbandoned here)

在上述场景中,由于 web 应用程序的上下文尚未被覆盖或包含,因此 logAbandoned=true 是否会应用于该上下文?或者仅应用 META-INF/context.xml 中设置的参数,而不应用主 context.xml 中设置的任何参数。

谢谢

最佳答案

Apache's documentation :

Default Context elements may be defined that apply to multiple web applications. Configuration for an individual web application will override anything configured in one of these defaults. Any nested elements, e.g. elements, that are defined in a default Context will be created once for each Context to which the default applies. They will not be shared between Context elements.

  • In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all web applications.
  • In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all web applications of that host.

因此,看起来主上下文首先应用于所有应用程序,然后应用模块的上下文,覆盖默认 context.xml 中匹配的任何上下文元素。

关于java - Tomcat的上下文层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17657509/

相关文章:

java - 使用 HTML 在 TextView 中设置图像上方的文本

tomcat - Nginx 和 Tomcat - 子域指向子目录

tomcat - Liferay/Tomcat : Where do I put my own selection of spring-framework jars?

rest - ActiveMQ REST API URI?

java - 为什么根证书不受 Java 客户端信任,即使它已经在 cacerts keystore 中

java - 断言 List<webelement> 中的元素包含一些文本

java - GWT + Glassfish 4 : Error 404 for RPC servlet

java - 用Java处理html日期输入

java - 使用相同的 servlet 上下文设置多个 Web 服务

Java - 如何阻止用户输入整数以外的内容?