Use Web Slices (Servlet API 3.0) in a Huge Project Environment

We recently switched to Servlet API 3.0. Since we develop a structure that sometimes needs several changes in web.xml , projects based on our structure should update their web.xml whenever a structure change occurs.

Servlet API 3.0 introduces new web fragments that make this behavior more loosely coupled and dynamic. I create web-fragment.xml and move all our materials from web.xml. Thus, now projects should only define the following web.xml and their own additional ads.

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" metadata-complete="false" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 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"> </web-app> 

We must use metadata-complete="false" to enable fragment search in the JAR (our structure has web-fragment.xml in META-INF/ .

Since we have a lot of dependencies on other frameworks and libraries (about 80-90), and metadata-complete="false" also starts the search for annotations, it takes an invalid 12 seconds to search all libraries.

The mechanism, since it works great, and I like the fact that we are more separate from our structure, but the startup time is fatal! We also need to increase the available memory for Tomcat from -Xms256m -Xmx512m to -Xms512m -Xmx1024m to start it without receiving java.lang.OutOfMemoryError: Java heap space (caused by an ineffective Tomcat annotation processor (about 50,000 classes are cached)).


I know that we can turn off the search for annotations in the library, but since we mainly use third-party ones that do not have the metadata-complete="true" flag, this is also not an option.

Can we do anything to turn off annotation search? Or can we make the servlet container look only in the declared libraries for web-fragment.xml ?

I would really like to use the new web fragment feature, but with increased startup time and memory, this is not possible.

+6
source share
2 answers

You can disable configuration annotation processing for specific JAR files. I used it only for JAR files, it may not work for exploded WAR s. See <tomcat>/conf/catalina.properties , line 76 (Tomcat 7.0.22):

 # List of JAR files that should not be scanned for configuration information # such as web fragments, TLD files etc. It must be a comma separated list of # JAR file names. # The JARs listed below include: # - Tomcat Bootstrap JARs # - Tomcat API JARs # - Catalina JARs # - Jasper JARs # - Tomcat JARs # - Common non-Tomcat JARs # - Sun JDK JARs # - Apple JDK JARs 
+3
source

Tomcat has some system properties that allow you to control JAR scans from 7.0.30. Check out the doc page here .

Mainly:

  • tomcat.util.scan.DefaultJarScanner.jarsToSkip
  • org.apache.catalina.startup.ContextConfig.jarsToSkip
  • org.apache.catalina.startup.TldConfig.jarsToSkip

Not sure if you can set ContextListener at the earliest time?

0
source

Source: https://habr.com/ru/post/909985/


All Articles