这里只做简要的记录,更详细的使用方式,更详细的资料参见spring参考文档(21.15 Code-based Servlet container initialization),以后会慢慢补充。
21.15 Code-based Servlet container initialization In a Servlet 3.0+ environment, you have the option of configuring the Servlet container programmatically as an alternative or in combination with a web.xml file. Below is an example of registering a DispatcherServlet:
WebApplicationInitializer is an interface provided by Spring MVC that ensures your implementation is detected and automatically used to initialize any Servlet 3 container. An abstract base class implementation of WebApplicationInitializer named AbstractDispatcherServletInitializer makes it even easier to register the DispatcherServlet by simply overriding methods to specify the servlet mapping and the location of the DispatcherServlet configuration:
The above example is for an application that uses Java-based Spring configuration. If using XML-based Spring configuration, extend directly from AbstractDispatcherServletInitializer:
AbstractDispatcherServletInitializer also provides a convenient way to add Filter instances and have them automatically mapped to the DispatcherServlet:
Each filter is added with a default name based on its concrete type and automatically mapped to the DispatcherServlet. The isAsyncSupported protected method of AbstractDispatcherServletInitializer provides a single place to enable async support on the DispatcherServlet and all filters mapped to it. By default this flag is set to true. Finally, if you need to further customize the DispatcherServlet itself, you can override the createDispatcherServlet method. 来自: http://my.oschina.net/u/1011578/blog/601719 |
小黑屋|在路上
( 蜀ICP备15035742号-1 )
GMT+8, 2025-7-9 07:55
Copyright 2015-2025 djqfx