哪个 Tomcat 5 上下文文件优先? [英] Which Tomcat 5 context file takes precedence?
问题描述
Tomcat 文档 说:
上下文描述符的位置是;
$CATALINA_HOME/conf/[引擎名]/[主机名]/context.xml
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml
在我的服务器上,我至少有 3 个文件在浮动:
1 ...tomcat/conf/context.xml2 ...tomcat/Catalina/localhost/myapp.xml3 ...tomcat/webapps/myapp/META-INF/context.xml
优先顺序是什么?
对于您列出的文件,假设您使用所有默认值的简单答案,顺序是(注意 conf/Catalina/本地主机):
...tomcat/conf/context.xml...tomcat/conf/Catalina/localhost/myapp.xml...tomcat/webapps/myapp/META-INF/context.xml
我将此(以及以下讨论)基于 Tomcat5.5 Context Container 的官方文档.
如果这是简单的答案,那么完整的答案是什么?
雄猫 5.5.将在其他几个地方查找 <Context>
元素,超出您列出的元素(请参阅官方文档).
如果 Tomcat 找到 Catalina/localhost/myapp.xml
,META-INF/context.xml
将永远不会被打开.因此,如果您确实拥有上述所有文件,则更正确的说法是 META-INF/context.xml
无关,而不是它的优先级最低.>
如果您在 Catalina/localhost/myapp.xml
中说 <Context override="true" ...>
这将使它成为 最高优先级,与 conf/context.xml
无关.只要您没有 Catalina/localhost/myapp.xml
(请参阅上一段),META-INFcontext.xml
中的内容相同.>
此外,上述文件中路径的 /Catalina/localhost/
部分实际上来自默认"conf/server.xml
并匹配
.如果您的 server.xml
在
中为 name
和 defaultHost
使用不同的值,那就是目录Tomcat 所在的结构.
最后,对于您列出的文件的 ...tomcat
部分,Tomcat 使用来自 $CATALINA_BASE
环境变量的目录.如果未设置,则它使用 $CATALINA_HOME
环境变量中的目录,该目录是 Tomcat 安装目录.我喜欢设置和使用 $CATALINA_BASE
这样我就不会污染"我的 Tomcat 安装.
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?
For the files you listed, the simple answer assuming you are using all the defaults, the order is (note the conf/Catalina/localhost):
...tomcat/conf/context.xml
...tomcat/conf/Catalina/localhost/myapp.xml
...tomcat/webapps/myapp/META-INF/context.xml
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 a Catalina/localhost/myapp.xml
. So if you actually have all the files above, its more correct to say the the META-INF/context.xml
is irrelevant, not that it's the lowest precedence.
If you say <Context override="true" ...>
in your Catalina/localhost/myapp.xml
that will make it the highest precedence, regardless of conf/context.xml
. Same thing in your META-INFcontext.xml
, as long as you don't have a Catalina/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 your server.xml
uses different values for name
and defaultHost
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.
这篇关于哪个 Tomcat 5 上下文文件优先?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!