哪个 Tomcat 5 上下文文件优先?
Tomcat 文档 说:
上下文描述符的位置是;
$CATALINA_HOME/conf/[引擎名]/[主机名]/context.xml
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml
在我的服务器上,我至少有 3 个文件:
1 ...tomcat/conf/context.xml
2 ...tomcat/Catalina/localhost/myapp.xml
3 ...tomcat/webapps/myapp/META-INF/context.xml
优先级顺序是什么?
Tomcat documentation says:
The locations for Context Descriptors are;
$CATALINA_HOME/conf/[enginename]/[hostname]/context.xml
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml
On my server, I have at least 3 files floating around:
1 ...tomcat/conf/context.xml
2 ...tomcat/Catalina/localhost/myapp.xml
3 ...tomcat/webapps/myapp/META-INF/context.xml
What is the order of precedence?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于您列出的文件,假设您使用所有默认值,简单的答案是,顺序是(注意 conf/Catalina/localhost):
我将此(以及以下讨论)基于上下文容器的 Tomcat 5.5 官方文档。
那么,如果这是简单的答案,那么完整的答案是什么?
雄猫 5.5。 除了您列出的元素之外,还将在其他几个地方查找
元素(请参阅官方文档)。如果 Tomcat 找到
Catalina/localhost/myapp.xml
,则META-INF/context.xml
将永远不会打开。 因此,如果您实际上拥有上述所有文件,更正确的说法是META-INF/context.xml
是不相关,而不是说它是最低优先级。如果您在
Catalina/localhost/myapp.xml
中输入
,这将使其成为最高conf/context.xml 为何。 只要您没有Catalina/localhost/myapp.xml
(请参阅上一段),您的META-INF\context.xml
中也会有同样的情况。此外,上面文件中路径的
/Catalina/localhost/
部分实际上来自“默认”conf/server.xml
并与< 匹配;引擎名称=“Catalina”defaultHost=“localhost”>
。 如果您的server.xml
在
中对name
和defaultHost
使用不同的值,则该目录是Tomcat 将查找的结构。最后,对于列出的文件的
...tomcat\
部分,Tomcat 使用$CATALINA_BASE
环境变量中的目录。 如果未设置,则会使用 $CATALINA_HOME 环境变量中的目录,即 Tomcat 安装目录。 我喜欢设置和使用$CATALINA_BASE
这样我就不会“污染”我的 Tomcat 安装。For the files you listed, the simple answer assuming you are using all the defaults, the order is (note the conf/Catalina/localhost):
I'm basing this (and the following discussion) on the Tomcat 5.5 official documentation for the Context Container.
So if that's the simple answer, whats the complete answer?
Tomcat 5.5. will look in a couple of other places for
<Context>
elements beyond those you've listed (see the official docs).The
META-INF/context.xml
will never be opened if Tomcat finds aCatalina/localhost/myapp.xml
. So if you actually have all the files above, its more correct to say the theMETA-INF/context.xml
is irrelevant, not that it's the lowest precedence.If you say
<Context override="true" ...>
in yourCatalina/localhost/myapp.xml
that will make it the highest precedence, regardless ofconf/context.xml
. Same thing in yourMETA-INF\context.xml
, as long as you don't have aCatalina/localhost/myapp.xml
(see previous paragraph).Also, the
/Catalina/localhost/
portion of the path in the files above actually comes out of the "default"conf/server.xml
and matches the<Engine name="Catalina" defaultHost="localhost">
. If yourserver.xml
uses different values forname
anddefaultHost
in the<Engine>
, that's the dir structure where Tomcat will look.Finally, for the
...tomcat\
portion of the files you listed, Tomcat uses the dir from the$CATALINA_BASE
environment variable. If that's not set, then it uses the dir from the$CATALINA_HOME
environment variable, which is the directory of the Tomcat installation. I like to set and use$CATALINA_BASE
so that I don't "pollute" my Tomcat installation.我的理解是:
My understanding is:
我没有找到任何官方文档,但我观察到加载顺序是:
其中 #2 是最后应用的一个(因此它的设置会覆盖所有先前的设置(如果适用))。
我从未使用过名为上下文文件的 Web 应用程序(您的选项#2)。
I haven't found any official documentation, but I have observed the load order to be:
Where #2 is the last one applied (so its settings override all previous ones, where applicable).
I have never used the webapp named context files (your option #2).