Skip to content

Instantly share code, notes, and snippets.

@keesun
Created April 2, 2012 13:50
Show Gist options
  • Select an option

  • Save keesun/2283540 to your computer and use it in GitHub Desktop.

Select an option

Save keesun/2283540 to your computer and use it in GitHub Desktop.
Spring 3.1's WebApplicationInitializer Sample
public class SampleWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext();
// ac.register(AppConfig.java);
ServletContextListener listener = new ContextLoaderListener(ac);
servletContext.addListener(listener);
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
// ac.register(WebConfig.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/app");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment