Created
May 18, 2012 21:33
-
-
Save frow/2727706 to your computer and use it in GitHub Desktop.
The Web App Initializer
This file contains hidden or 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 WebAppInitializer implements WebApplicationInitializer { | |
@Override | |
public void onStartup(ServletContext servletContext) | |
throws ServletException { | |
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); | |
rootContext.register(RootConfig.class); | |
servletContext.addListener(new ContextLoaderListener(rootContext)); | |
servletContext.setInitParameter("defaultHtmlEscape", "true"); | |
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); | |
mvcContext.register(WebMvcConfig.class); | |
ServletRegistration.Dynamic appServlet = servletContext.addServlet( | |
"appServlet", new DispatcherServlet(mvcContext)); | |
appServlet.setLoadOnStartup(1); | |
Set<String> mappingConflicts = appServlet.addMapping("/"); | |
if (!mappingConflicts.isEmpty()) { | |
throw new IllegalStateException( | |
"'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment