What to do with annotations after setting metadata-complete=“true” (which resolved slow Tomcat 7 start-up)?

前端 未结 2 1014
轻奢々
轻奢々 2020-12-07 13:49

Seems like the slow Tomcat 7 startup problem can be resolved with \"metadata-complete\" set to \"true\" in the web.xml, like so:



        
相关标签:
2条回答
  • 2020-12-07 14:30

    The slow startup is caused because every single class file in every single JAR file in /WEB-INF/lib is also scanned for Servlet 3.0 specific annotations. You apparently have a lot of (large) JAR files in /WEB-INF/lib.

    The metadata-complete="true" indicates that the JAR files in /WEB-INF/lib doesn't need to be scanned for Servlet 3.0 specific annotations, but the webapp's own classes will still be scanned.

    Note that you listed there two JSF annotations and one Java SE annotation, not any Servlet 3.0 annotations. The Servlet 3.0 annotations are listed in the javax.servlet.annotation package. JSF will only scan for annotations when the JAR file contains a JSF 2.0 compatible /META-INF/faces-config.xml file. It won't immediately scan every single class in every JAR file. The Java SE @Override annotation is not a runtime annotation, but a compile-time aid only.

    See also:

    • Packaging Facelets files (templates, includes, composites) in a JAR
    0 讨论(0)
  • 2020-12-07 14:31

    Here is what Java Servlet 3.0 / 3.1 Specification has to say:

    The web application deployment descriptor contains a metadata-complete attribute on the web-app element. The metadata-complete attribute defines whether the web.xml descriptor is complete, or whether other sources of metadata used by the deployment process should be considered. Metadata may come from the web.xml file, web-fragment.xml files, annotations on class files in WEB-INF/classes, and annotations on classes in jar files in the WEB-INF/lib directory. If metadata-complete is set to "true", the deployment tool only examines the web.xml file and must ignore annotations such as @WebServlet, @WebFilter, and @WebListener present in the class files of the application, and must also ignore any web-fragment.xml descriptor packaged in a jar file in WEB-INF/lib. If the metadata-complete attribute is not specified or is set to "false", the deployment tool must examine the class files and web-fragment.xml files for metadata,as previously specified.

    This being said and to answer your question: Yes, in order to optimise the start up time of Tomcat you need to use metadata-complete="true" and put every Servlet or Filter or Listener in your deployment descriptor.

    0 讨论(0)
提交回复
热议问题