java Tomcat 7 慢启动 metadata-complete="true" web.xml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17656398/
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-11-01 14:34:18  来源:igfitidea点击:

Tomcat 7 slow start metadata-complete="true" web.xml

javametadatatomcat7web.xml

提问by chiperortiz

i have migrated to Tomcat 7[7.0.4.1] in the past a startUp takes between 5 or 7 seconds now takes 30 seconds i have read on other post metadata-complete="true" set in the web.xml solves the trick but seems not solved in my case i have added metadata-complete="true"in WEB-INF/web.xmland in tomcat/conf/web.xmlneither seems to work.

我已经迁移到 Tomcat 7[7.0.4.1] 过去启动需要 5 到 7 秒,现在需要 30 秒我已经阅读了 web.xml 中设置的其他帖子 metadata-complete="true" 解决了这个问题,但似乎在我的情况不解决我已经添加metadata-complete="true"WEB-INF/web.xmltomcat/conf/web.xml没有似乎工作。

here is the code for tomcat/conf/web.xml

这是代码 tomcat/conf/web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true"
version="3.0">

here is the code for WEB-INF/web.xml

这是代码 WEB-INF/web.xml

<web-app metadata-complete="true" version="3.0"  xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

the deploying is being sucessfully here is the trace tomcat is printing.

部署正在成功,这里是 tomcat 正在打印的跟踪。

INFO: Starting Servlet Engine: Apache Tomcat/7.0.41
jul 22, 2013 4:33:08 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath

in this sentence is taking over 30 seconds..

在这句话中需要超过 30 秒..

INFO: Starting Servlet Engine: Apache Tomcat/7.0.41

my questions are:

我的问题是:

  • what i am doing wrong??

  • how can i see is metadata-complete is setting to true i am reading in others web-site this can be made checking the flag in isMetadataComplete()but my question is where or how can i call this method??

  • 我做错了什么??

  • 我如何才能看到元数据完整设置为 true 我正在其他网站上阅读这可以检查标志isMetadataComplete()但我的问题是我在哪里或如何调用此方法?

we are using [Spring,Hibernate,ZK]in out project.

我们在项目中使用[Spring,Hibernate,ZK]

回答by Prashant Saraswat

The metadata-complete didn't resolve my startup time issues either. The problem is that tomcat scans multiple (almost all jars) at startup for annotations and tld files. Of course, not all jars contains tld files and annotations. To improve your startup times you can exclude these jars. Something like the following should do the trick: Adjust conf/catalina.properties:

元数据完成也没有解决我的启动时间问题。问题是 tomcat 在启动时扫描多个(几乎所有 jars)以获取注释和 tld 文件。当然,并不是所有的 jars 都包含 tld 文件和注解。为了缩短启动时间,您可以排除这些 jar。像下面这样的东西应该可以解决问题:调整conf/catalina.properties:

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

# Additional JARs (over and above the default JARs listed above) to skip when
# scanning for TLDs. The list must be a comma separated list of JAR file names.
# The following list will make sure stuff like jstl and spring-webmvc.jar etc which contain tld files are included
org.apache.catalina.startup.TldConfig.jarsToSkip=a*.jar,b*.jar,c*.jar,d*.jar,e*.jar,f*.jar,g*.jar,h*.jar,i*.jar,jc*.jar, jd*.jar, je*.jar, jl*.jar, jo*.jar, JO*.jar, jr*.jar, jso*.jar, jsr*.jar, jts*.jar,k*.jar,l*.jar,m*.jar,n*.jar,o*.jar,p*.jar,q*.jar,r*.jar,spring-a*.jar, spring-c*.jar, spring-e*.jar, spring-j*.jar, spring-s*.jar, spring-test*.jar, stax*.jar, st*.jar, t*.jar,u*.jar,v*.jar,w*.jar,x*.jar,y*.jar,z*.jar

回答by Didier L

For those who might still encounter this issue like me (while migrating to Java 8 and from Spring 3.0 to 3.2), note that you will also run into the issue if any jar you use contains a web-fragment.xml(like spring-web).

对于像我这样可能仍然遇到这个问题的人(在迁移到 Java 8 和从 Spring 3.0 到 3.2 时),请注意,如果您使用的任何 jar 包含web-fragment.xml(如 spring-web),您也会遇到这个问题。

To avoid this, you should also specify an empty absolute-orderingin your web.xml(according to SPRING-10196and Tomcat's HowTo/FasterStartUp):

为了避免这种情况,您还应该absolute-ordering在您的web.xml(根据SPRING-10196和 Tomcat 的HowTo/FasterStartUp)中指定一个空

<absolute-ordering/>

(also make sure you are specifying servlet 3.0 in your web.xml)

(还要确保您在 web.xml 中指定了 servlet 3.0)

Also, if you are using an old version of Tomcat, an empty absolute-orderingwill not work due to bug 54262. To fix this, use a dummy fragment name:

此外,如果您使用的是旧版本的 Tomcat,absolute-ordering由于错误 54262,空文件将不起作用。要解决此问题,请使用虚拟片段名称:

<absolute-ordering>
    <!-- Due to a bug in Tomcat 7.0.29, an empty absolute-ordering does not prevent the annotation scanning.
    Adding a dummy fragment name does the trick.
    see proposed workaround in https://bz.apache.org/bugzilla/show_bug.cgi?id=54262#c0 -->
    <name>dummy</name>
</absolute-ordering>

If nothing works, consider the jarsToSkipsolution proposed by @Prashant, but this is more annoying since it requires to modify the Tomcat configuration in all your environments.

如果没有任何效果,请考虑jarsToSkip@Prashant 提出的解决方案,但这更烦人,因为它需要修改所有环境中的 Tomcat 配置。

(Since I am using an old version of Tomcat on Java 8, the annotation processing is completely broken for me, with lots of exceptions occurring at startup)

(由于我在 Java 8 上使用的是旧版本的 Tomcat,因此注释处理对我来说完全中断,启动时发生了很多异常)