定制 Tomcat 阀门配置
我写了一个定制的 Tomcat 阀门。 (我使用的是 Tomcat 6.0.24 和 Java 1.6)这是我声明阀门的 XML 元素:
<Valve className="mypkg.MyValve" foo="bar"/>
当我将此声明放入 server.xml 的 Host 元素中时。 Tomcat 使用值“bar”调用我的 Valve 上的 setFoo() 方法。这就是我想要发生的事情。
但是,当我将相同的声明放入 web 应用程序的 META-INF/context.xml 中的 Context 元素内时,Tomcat 会加载阀门并且阀门运行良好。但 Tomcat 从不调用 setFoo() 方法来提供阀门所需的“bar”值。
我不明白为什么 Tomcat 正确配置了在 server.xml 中声明的阀门,而不是在 context.xml 中声明的阀门。
有谁知道当我的 web 应用程序的 META-INF/context.xml 中声明了我的阀门时,如何让 Tomcat 正确配置我的阀门?
谢谢, Dan
这会导致我的阀门加载并由 Tomcat 正确配置:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="mypkg.MyValve" foo="bar"/>
</Host>
这会导致我的阀门加载,但 Tomcat 不会为其提供配置参数“bar”:
<Context privileged="true" >
<Valve className="mypkg.MyValve" foo="bar"/>
</Context>
I wrote a custom Tomcat valve. (I'm using Tomcat 6.0.24 and Java 1.6) Here's the XML element where I declare my valve:
<Valve className="mypkg.MyValve" foo="bar"/>
When I put this declaration inside server.xml's Host element. Tomcat calls the setFoo() method on my valve with the value "bar". That's what I want to happen.
However, when I put this same declaration in my webapp's META-INF/context.xml, inside the Context element, Tomcat loads the valve and the valve runs fine. But Tomcat never calls the setFoo() method to provide the "bar" value the valve needs.
I'm don't understand why Tomcat properly configures a valve declared in server.xml but not in context.xml.
Does anyone know how I can get Tomcat to properly configure my valve when it's declared in my webapp's META-INF/context.xml?
Thanks,
Dan
This causes my valve to load and be properly configured by Tomcat:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="mypkg.MyValve" foo="bar"/>
</Host>
This causes my valve to load, but Tomcat won't give it the config parameter "bar":
<Context privileged="true" >
<Valve className="mypkg.MyValve" foo="bar"/>
</Context>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我经过研究的猜测。您的
Valve
可能绑定到Host
容器吗?您的自定义阀门是否直接子类化
org.apache.catalina.valves.ValveBase
?如果是这样,它应该有效。
您可以尝试打印
getContainer()
在您的 Valve 上从您的两个设置中查看它是否正确识别了getContainer()
。 apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/Container.html" rel="nofollow noreferrer">Catalina 容器(引擎、主机、上下文) 设置为每次。某些 Valve,例如 SingleSignOn 绑定到像
Host
这样的容器,这意味着它不能在其他容器上工作。这也适用于子类阀门。This is my researched guess. It could be that your
Valve
is bound to theHost
container ?Is your custom valve directly subclassing
org.apache.catalina.valves.ValveBase
? If so, it should have worked.
You could try and print out the
getContainer()
on your Valve from both your settings to see if it correctly identifies which of the Catalina containers (Engine, Host, Context) it is set at each time.Certain Valves like SingleSignOn are bound to a container like
Host
which means it wont work on others. This will apply to subclassed Valves too.SetPropertiesRule 作为启动的一部分,将尝试为您的自定义属性查找 getter。
SetPropertiesRule, as part of the startup, will try to find getters for your custom properties.