java 是否可以在 Tomcat 中关闭 taglib 扫描?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1489665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:43:42  来源:igfitidea点击:

Is it possible to turn off taglib scanning in Tomcat?

javatomcattaglib

提问by Matt Passell

On startup, Tomcat recursively scans the WEB-INF directories for TLD (Tag Library Descriptor) files. As a result, if a webapp has a lot of files under that directory, it slows down the startup process. Does anyone know if there is a way in that situation to turn off scanning completely, or at least provide a filter to narrow the search?

启动时,Tomcat 递归扫描 WEB-INF 目录以查找 TLD(标记库描述符)文件。因此,如果一个 webapp 在该目录下有很多文件,它会减慢启动过程。有谁知道在这种情况下是否有办法完全关闭扫描,或者至少提供一个过滤器来缩小搜索范围?

回答by ZZ Coder

You can add processTlds attributes in the context,

您可以在上下文中添加 processTlds 属性,

  <Context processTlds="false" ... />

However, your TLDs defined in the JAR file wouldn't work without scanning the JARs. You have to define all TLDs in WEB-INF.

但是,如果不扫描 JAR,您在 JAR 文件中定义的 TLD 将无法工作。您必须在 WEB-INF 中定义所有 TLD。

回答by Igor Semenko

I was puzzled by the same problem. Looking into source code of Tomcat 7.0.40, it is not possible to avoid jars scanning by setting 'processTlds=false', they will still be scanned for web fragments (ContextConfig.processJarsForWebFragments()).

我对同样的问题感到困惑。查看 Tomcat 7.0.40 的源代码,无法通过设置“processTlds=false”来避免 jars 扫描,它们仍将被扫描以查找 Web 片段(ContextConfig.processJarsForWebFragments())。

There are 2 options remaining:

剩下2个选项:

Set property in TOMCAT_HOME/conf/catalina.properties

在 TOMCAT_HOME/conf/catalina.properties 中设置属性

org.apache.catalina.startup.ContextConfig.jarsToSkip=*.jar

Replace StandardJarScanner by your own implementation, for example empty one and refer to it from my.war/META-INF/context.xml:

用你自己的实现替换 StandardJarScanner,例如空一个并从 my.war/META-INF/context.xml 引用它:

<Context processTlds="false">
    <JarScanner className="org.my.tomcat.NullJarScanner"/>
</Context>

In latter case you'll need to make sure that NullJarScanner class is available in tomcat's lib directory, not your .war

在后一种情况下,您需要确保 NullJarScanner 类在 tomcat 的 lib 目录中可用,而不是您的 .war

回答by Sergey

On Tomcat 8 it can be solved by adding the META-INF\context.xmlwith the configuration seen below to your WAR file. No need to change the global Tomcat configuration.

在 Tomcat 8 上,它可以通过将META-INF\context.xml下面看到的配置添加到您的 WAR 文件中来解决。无需更改全局 Tomcat 配置。

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <JarScanner>
        <JarScanFilter tldSkip="*.*"/>
    </JarScanner>
</Context>

The relevant documentation is available here: http://tomcat.apache.org/tomcat-8.0-doc/config/jar-scan-filter.html

相关文档可在此处获得:http: //tomcat.apache.org/tomcat-8.0-doc/config/jar-scan-filter.html

回答by Vadim Ponomarev

As an alternative (if you still prefer to scan some JARs) you could append new values to "tomcat.util.scan.DefaultJarScanner.jarsToSkip" property in "{TOMCAT_HOME}/conf/catalina.properties".

作为替代方案(如果您仍然喜欢扫描一些 JAR),您可以将新值附加到“{TOMCAT_HOME}/conf/catalina.properties”中的“tomcat.util.scan.DefaultJarScanner.jarsToSkip”属性。