Servletcontainerinitializer and @handlestypes

Source: Internet
Author: User

The class that implements the Servletcontainerinitializer interface is passed in the jar package through the meta-inf\services\ A file named Javax.servlet.ServletContainerInitializer is identified later in the container when the servlet container is started.

Springservletcontainerinitializer Java doc JAR Services API ServiceLoader.load(Class) method detecting the spring-web module ' s META-INF/services/javax.servlet.ServletContainerInitializer Service Pro Vider configuration file. See the JAR Services API documentation as well as sections 8.2.4 of the Servlet 3.0 Final Draft specification fo R complete details.

@HandlesTypes:

This annotation was used to declare an array of application classes which was passed to a javax.servlet.ServletContainerInitializer .

Springservletcontainerinitializer.onstartup (webappinitializerclasses, ServletContext); Java Doc:

Delegate the ServletContext WebApplicationInitializer implementations present on the application classpath.

Because This class declares @ HandlesTypes(WebApplicationInitializer.class) , Servlet 3.0+ containers would automatically scan the classpath for implementations of S Pring ' s interface and provide the set of all such types to the parameter of this WebApplicationInitializer webAppInitializerClasses method.

If No WebApplicationInitializer implementations is found on the Classpath, this method is effectively a no-op. An info-level log message would be issued notifying the user that the have ServletContainerInitializer indeed been invoked but that no WebApplicationInitializer imple Mentations were found.

Assuming that one or more WebApplicationInitializer types is detected, they would be instantiated (and sorted if the @ @Order annotatio n is present or the Ordered interface have been implemented). Then the WebApplicationInitializer.onStartup(ServletContext) method is invoked on each instance, delegating the such so each ServletContext instance may register and Conf Igure servlets such as Spring ' s DispatcherServlet , listeners such as Spring ' s ContextLoaderListener , or any other Servlet API componentry such as Fil Ters.

configures the pluggable nature of the runtime/shared library by using the @ handlestypes annotation.

Servletcontainerinitializer and @handlestypes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.