Tomcat 7上下文参数覆盖 [英] Tomcat 7 context parameter override

查看:196
本文介绍了Tomcat 7上下文参数覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

context.xml文件看起来像

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

但我收到一个错误,说

  java.lang.IllegalArgumentException:文档库< path-to-tomcat> apache-tomcat-7.0.35 / webapps / context不存在或不是可读的目录

我把< Parameter name =portvalue =100override =1/> / code>在< tomcat-home> /context.xml ,然后就可以了。



解决方案

这是因为没有这样的应用程序上下文名称​​上下文。换句话说,没有将上下文名称的网络应用程序部署到 webapps 目录。



定义上下文相关的Tomcat 7文档:


个别上下文元素可以明确定义:




  • 单个文件在/META-INF/context.xml里面的应用程序文件。可选地(基于主机的copyXML属性)
    这可以被复制到$ CATALINA_BASE / conf / [enginename] / [hostname] /和
    被重命名为应用程序的基本文件名加上.xml扩展名。


  • 在$ CATALINA_BASE / conf / [enginename] / [hostname] /目录中的单个文件(带有.xml扩展名) 上下文
    路径和版本将从文件的基本名称(
    文件名减去.xml扩展名)派生。
    。这个文件总是优先于任何在web应用程序
    META-INF目录中打包的context.xml文件。


  • 主conf / server.xml中的主机元素。



工作,请将您的自定义文件命名为 context.xml ,而不是 your_app_name.xml

在您的情况下,

我已经测试过了。



myapp.xml



 code><?xml version =1.0encoding =UTF-8?> 
< Context>
< Parameter name =portvalue =100override =1/>
< / Context>








您可以在没有路径属性的情况下获取,因此不要包含它。

Apache Pache Tomcat 7文档


此属性只能在
server.xml
中静态定义上下文时使用。在所有其他情况下,路径将从
推断用于.xml上下文文件或docBase的文件名。



即使静态在server.xml中定义一个Context,这个属性
不能被设置,除非docBase不在
Host的appBase下,或者deployOnStartup和autoDeploy都是false
。如果
不遵循此规则,则可能导致双重部署。



I am trying to override a parameter in my application's web.xml file by creating a context.xml file in <tomcatHome>/conf/Catalina/localhost

The context.xml file looks like

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

but I get an error saying

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

If I put the <Parameter name="port" value="100" override="1"/> directly in the context.xml in <tomcat-home>/context.xml then it works.

Can someon explain what I am doing incorrectly?

解决方案

It is because there is no such application context with the name context. In other words there is no web app with the name context deployed to the webapps directory.

Form the official Tomcat 7 documentation related to Defining a context:

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.

So to make it work, name your custom file not context.xml, but your_app_name.xml.
In your case it will be (if I understood you correctly) myapp.xml.

This should work. I have just tested it.

myapp.xml

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


P.S.

And you can get without path attribute, so don't include it.
From the 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.

这篇关于Tomcat 7上下文参数覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆