Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.xml and in tomcat/conf/web.xml neither seems to work.

here is the code for 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-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.

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..

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??

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

like image 401
chiperortiz Avatar asked Jul 15 '13 14:07

chiperortiz


2 Answers

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:

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
like image 110
Prashant Saraswat Avatar answered Oct 02 '22 06:10

Prashant Saraswat


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).

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

<absolute-ordering/>

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

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

<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 jarsToSkip solution proposed by @Prashant, but this is more annoying since it requires to modify the Tomcat configuration in all your environments.

(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)

like image 20
Didier L Avatar answered Oct 02 '22 06:10

Didier L