gpt4 book ai didi

java - Tomcat 7 上下文参数覆盖

转载 作者:搜寻专家 更新时间:2023-11-01 01:54:17 24 4
gpt4 key购买 nike

我试图通过在 <tomcatHome>/conf/Catalina/localhost 中创建一个 context.xml 文件来覆盖我应用程序的 web.xml 文件中的一个参数。

context.xml 文件看起来像

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myapp">
<Parameter name="port" value="100" override="1"/>
</Context>

但是我得到一个错误提示

java.lang.IllegalArgumentException: Document base <path-to-tomcat> apache-tomcat-7.0.35/webapps/context does not exist or is not a readable directory

如果我把 <Parameter name="port" value="100" override="1"/>直接在 context.xml<tomcat-home>/context.xml然后就可以了。

谁能解释一下我做错了什么?

最佳答案

这是因为不存在名为context 的应用上下文。换句话说,没有名为 context 的 Web 应用部署到 webapps 目录。

形成与Defining a context相关的官方Tomcat 7文档:

Individual Context elements may be explicitly defined:

  • In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.

  • In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.

  • Inside a Host element in the main conf/server.xml.

因此,要使其正常工作,请将您的自定义文件命名为context.xml,而是your_app_name.xml
在您的情况下,它将是(如果我理解正确的话)myapp.xml

这应该有效。我刚测试过。

myapp.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Parameter name="port" value="100" override="1"/>
</Context>

附言

你可以在没有path属性的情况下获取,所以不要包含它。
来自Apache Tomcat 7 documentation :

This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.

Even when statically defining a Context in server.xml, this attribute must not be set unless either the docBase is not located under the Host's appBase or both deployOnStartup and autoDeploy are false. If this rule is not followed, double deployment is likely to result.

关于java - Tomcat 7 上下文参数覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com