Created
November 24, 2011 05:10
-
-
Save keesun/1390672 to your computer and use it in GitHub Desktop.
Spring 3.1's MVC Web Application Initializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebAppIntializer implements WebApplicationInitializer { | |
@Override | |
public void onStartup(ServletContext servletContext) throws ServletException { | |
//parent | |
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); | |
rootContext.register(AppConfig.class); | |
servletContext.addListener(new ContextLoaderListener(rootContext)); | |
// new ContextLoader(rootContext).initWebApplicationContext(servletContext); | |
//child | |
AnnotationConfigWebApplicationContext dispatcherServletContext = new AnnotationConfigWebApplicationContext(); | |
dispatcherServletContext.register(WebConfig.class); | |
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", new DispatcherServlet(dispatcherServletContext)); | |
dispatcher.setLoadOnStartup(1); | |
dispatcher.addMapping("/"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment