@Override
public void onStartup (ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx =
new AnnotationConfigWebApplicationContext();
//register our config class
ctx.register(MyWebConfig.class);
ctx.setServletContext(servletContext);
//using servlet 3 api to dynamically create
//spring dispatcher servlet
ServletRegistration.Dynamic servlet =
servletContext.addServlet("springDispatcherServlet",
new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}