简体   繁体   English

用以下方法配置tomcat上下文文件的替代方法是什么<Loader delegate = true />

[英]What is the alternative way for configuring tomcat context file with <Loader delegate = true />

I'm working on a web application recently I faced with an issue of ClassCastException, found that same class been loaded by two different ClassLoaders. 我最近在处理一个Web应用程序,遇到一个ClassCastException问题,发现同一类由两个不同的ClassLoader加载。 I'm not able to reproduce this issue in cluster. 我无法在群集中重现此问题。 I'm facing this issue only in the Local environment. 我仅在本地环境中面临此问题。 I configured the Tomcat Context.xml with <Loader delegate =true /> This solves my ClassCastException issue with proper ClassLoading mechanism as mentioned here . 我使用<Loader delegate =true />配置了Tomcat Context.xml,这使用此处提到的适当的ClassLoading机制解决了ClassCastException问题。 Now since it is already working fine in the Cluster I dont want to make changes in the context.xml. 现在,由于它已经在集群中正常工作了,所以我不想在context.xml中进行更改。 So is there any alternative way. 有没有其他选择的方法。

As per the Tomcat documentation, 根据Tomcat文档,

"A Loader element MAY be nested inside a Context component. If it is not included, a default Loader configuration will be created automatically." “一个Loader元素可以嵌套在Context组件内。如果不包含它,则将自动创建默认的Loader配置。”

So, you can do this in server.xml without changing the Context.xml file. 因此,您可以在server.xml中执行此操作,而无需更改Context.xml文件。

        <Context path="" docBase="" debug="0">
            <Loader delegate="true"/>
        </Context> 

Cheers, 干杯,

否。配置委托的唯一方法是通过嵌套在Context元素内的Loader元素。

The standard implementation of Loader is org.apache.catalina.loader.WebappLoader. Loader的标准实现是org.apache.catalina.loader.WebappLoader。 It supports the attribute loaderClass. 它支持属性loaderClass。

Custom implementations must extend org.apache.catalina.loader.WebappClassLoaderBase 自定义实现必须扩展org.apache.catalina.loader.WebappClassLoaderBase

@see https://tomcat.apache.org/tomcat-8.0-doc/config/loader.html @请参阅https://tomcat.apache.org/tomcat-8.0-doc/config/loader.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM