/** * see the javadoc of {@link WebApplicationInitializer} * * WebApplicationInitializer 是Spring提供用来配置Servlet 3.0配置的接口,从而实现替代web.xml的位置。 * 实现此接口将会自动被SpringServletContainerInitializer (用来启动Servlet 3.0 容器)获取到。 * */ /*public class WebInitializer implements WebApplicationInitializer { public void onStartup(ServletContext servletContext) throws ServletException { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.setServletContext(servletContext); rootContext.register(WebMvcConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }*/
/** * 采用模板方法模式,具体逻辑同上述代码相同 * for getRootConfigClasses, you can see {@link AbstractAnnotationConfigDispatcherServletInitializer .createRootApplicationContext()} * for getServletConfigClasses, you can see {@link AbstractAnnotationConfigDispatcherServletInitializer .createServletApplicationContext()} * for getServletMappings , you can see {@link `AbstractDispatcherServletInitializer.registerDispatcherServlet()`} * * */ publicclassWebAppInitializerextendsAbstractAnnotationConfigDispatcherServletInitializer {