Custom Tomcat Valve contained in web app WAR file

◇◆丶佛笑我妖孽 提交于 2019-12-01 02:23:33

问题


I'm looking to implement a custom Valve and configuring it using META-INF/context.xml.

At the moment though, when context.xml is parsed during deployment, Tomcat (6.0.32) dies with a ClassNotFoundException on my custom Valve implementation.

I'm under the impression that I'm running into a class loading context issue and I'm not 100% sure I understand it.

Is my class not found because it is located in the WEB-INF/classes file and the Context level class loader is unable to locate the class because of the hierarchy?

Thanks in advance.


回答1:


You can not load Valves from inside the webapp class loader. If you look at http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html it shows the available class loaders. You must use one of the Bootstrap, System or Common classloaders because Valve definitions are processed BEFORE the individual webapp classloaders are created: the Context has to be processed before the webapp is available.

Package your Valve in a jar by itself and copy it into the $CATALINA_HOME/lib folder and you should be all set.



来源:https://stackoverflow.com/questions/6138396/custom-tomcat-valve-contained-in-web-app-war-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!