Context可以存在的地方有4个。
- tomcatdir/conf/server.xml
- tomcatdir/conf/context.xml
- tomcatdir/conf/Catalina/localhost/appname.xml
- tomcatdir/webapps/appname/META-INF/context.xml
在 tomcat 8 的情况下,allowlinking 属性不应在 Context 中指定,而应在 Resources 标签中指定。我的 tomcatdir/conf/context.xml 看起来像这样
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Resources allowLinking="true" cachingAllowed="true" cacheMaxSize="100000" />
</Context>
这个解决方案现在对我来说很好。但我也想分享我在提出这个解决方案之前犯的错误。
我在 tomcatdir/conf/server.xml 和 tomcatdir/conf/context.xml 中都定义了资源。并且仅在 tomcatdir/conf/server.xml 中设置了 allowLinking="true"。
我发现如果您不指定allowLinking,则等于将其设置为false。所以我从 server.xml 中删除了 Resources 标签,只留下了 tomcatdir/conf/context.xml,其中包含 allowLinking="true" 属性。