我正在使用 tomcat 9,并尝试从 PreResources 标记下面加载所有与项目相关的 jar。
<Resources className="org.apache.catalina.webresources.StandardRoot" cachingAllowed="true" cacheMaxSize="100000" allowLinking="true">
<PreResources className="org.apache.catalina.webresources.DirResourceSet"
base="D:\SomePath\apache-tomcat-9.0.0.M17-windows-x64-2\apache-tomcat-9.0.0.M17"
internalPath="/External-lib"
webAppMount="/WEB-INF/classes" />
根据“base”中提到的路径,External-lib 文件夹位于 tomcat 目录中。但是当部署应用程序时,我收到以下错误。
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
这从 web.xml 调用,
org.springframework.web.context.ContextLoaderListener
在 tomcat lib 中,我们只有 tomcat 库,其余所有 jar 都位于External-lib 文件夹中。由于我们有类似的 webApp 并且 jar 太多,我们正在尝试将它们外部化,而不是加载到 webapp/web-inf/lib 文件夹中。
请建议,使用 PreResources 元素从 meta-inf/context.xml 加载 jar 时是否遗漏了任何内容。
此 PreResources 元素的示例和文档非常少。 任何指导或帮助将不胜感激。
最佳答案
这应该是context.xml的内容。它有效并解决了我的问题。
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resources>
<PreResources className="org.apache.catalina.webresources.DirResourceSet"
base="SomePath\External-lib\"
webAppMount="/WEB-INF/lib" />
</Resources>
</Context>
“Base”是外部资源的路径,“webAppMount”是您要挂载这些资源的位置。
关于java - Tomcat : PreResources tag not loading jars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44332597/