Skip to content

Instantly share code, notes, and snippets.

@igm
Created November 4, 2011 14:36
Show Gist options
  • Save igm/1339463 to your computer and use it in GitHub Desktop.
Save igm/1339463 to your computer and use it in GitHub Desktop.
Spring 3.1 WebApplication Initialization
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class ContextInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
Dynamic servlet = servletContext.addServlet("dis", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment