We have an application which keeps loading instances of ServletContainerInitializer from our 3rd party libs.
One instance is JerseyServletContainerInitializer and the other is SpringServletContainerInitializer. These classes from Jersey and Spring seem to "take over" our servlet context messing with our mappings and filters and such.
We really need to explicitly configure our servlet container's web.xml and this auto scanning is driving us insane. By simply pulling in a dependency in our pom.xml our runtime ServletContext configurations such as Servlets/Filters/ContextListeners are mutated because the servlet container finds these libraries on the classpath.
Is there a way to use Servlet 3 but disable its annoying auto classpath scanning "feature"?
Annotation Type ServletComponentScanEnables scanning for Servlet components ( filters , servlets , and listeners ). Scanning is only performed when using an embedded web server. Typically, one of value , basePackages , or basePackageClasses should be specified to control the packages to be scanned for components.
The absolute order is a natural partial order on a Coxeter group W. It can be viewed as an analogue of the weak order on W in which the role of the generating set of simple reflections in W is played by the set of all reflections in W.
Your specify absolute ordering using the <absolute-ordering> element in the web. xml file. You specify relative ordering with an <ordering> element in the web-fragment. xml file.
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.
From https://wiki.apache.org/tomcat/HowTo/FasterStartUp
There are two options that can be specified in your WEB-INF/web.xml file:
- Set metadata-complete="true" attribute on the <web-app> element.
- Add an empty <absolute-ordering /> element.
Setting metadata-complete="true" disables scanning your web application and its libraries for classes that use annotations to define components of a web application (Servlets etc.). The metadata-complete option is not enough to disable all of annotation scanning. If there is a SCI with a @HandlesTypes annotation, Tomcat has to scan your application for classes that use annotations or interfaces specified in that annotation.
The <absolute-ordering> element specifies which web fragment JARs (according to the names in their WEB-INF/web-fragment.xml files) have to be scanned for SCIs, fragments and annotations. An empty element configures that none are to be scanned.
In Tomcat 7 the absolute-ordering option affects discovery both of SCIs provided by web application and ones provided by the container (i.e. by the libraries in $CATALINA_HOME/lib). In Tomcat 8 the option affects the web application ones only, while the container-provided SCIs are always discovered, regardless of absolute-ordering. In such case the absolute-ordering option alone does not prevent scanning for annotations, but the list of JARs to be scanned will be empty, and thus the scanning will complete quickly. The classes in WEB-INF/classes are always scanned regardless of absolute-ordering.
Scanning for web application resources and TLD scanning are not affected by these options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With