Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2011 17:49
Show Gist options
  • Save anonymous/1033325 to your computer and use it in GitHub Desktop.
Save anonymous/1033325 to your computer and use it in GitHub Desktop.
Java-based conatiner configuration with no web.xml.
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext container) throws ServletException {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(RootContext.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(mytld.mycompany.myapp.config.appServlet.ServletContext.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = container.addServlet(
"appServlet", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/main");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment