码迷,mamicode.com
首页 > 其他好文 > 详细

ServletContainerInitializer与@HandlesTypes

时间:2015-11-08 22:33:48      阅读:1446      评论:0      收藏:0      [点我收藏+]

标签:

实现ServletContainerInitializer接口的类,在jar包中通过在META-INF\services\下的一个叫做javax.servlet.ServletContainerInitializer的文件中指明后在servlet容器启动时候会被容器发现.

SpringServletContainerInitializer java doc   JAR Services API ServiceLoader.load(Class) method detecting the  spring-web module‘s META-INF/services/javax.servlet.ServletContainerInitializer service provider configuration file. See the   JAR Services API documentation as well as section 8.2.4 of the Servlet 3.0 Final Draft specification for complete details. 


@HandlesTypes:

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

springServletContainerInitializer.onStartup(webAppInitializerClasses, servletContext); java doc:

Delegate the ServletContext to any WebApplicationInitializer implementations present on the application classpath.

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

If no WebApplicationInitializer implementations are found on the classpath, this method is effectively a no-op. An INFO-level log message will be issued notifying the user that the ServletContainerInitializer has indeed been invoked but that no WebApplicationInitializer implementations were found.

Assuming that one or more WebApplicationInitializer types are detected, they will be instantiated (and sorted if the @@Order annotation is present or the Ordered interface has been implemented). Then the WebApplicationInitializer.onStartup(ServletContext) method will be invoked on each instance, delegating the ServletContext such that each instance may register and configure servlets such as Spring‘s  DispatcherServlet, listeners such as Spring‘s ContextLoaderListener, or any other Servlet API componentry such as filters.

通过使用@HandlesTypes注解配置运行时/共享库的可插拔性.

ServletContainerInitializer与@HandlesTypes

标签:

原文地址:http://my.oschina.net/fuckmylife0/blog/527793

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!