// creates the web root app context
AnnotationConfigWebApplicationContext webRootContext = new AnnotationConfigWebApplicationContext();
webRootContext.register(WebAppConfig.class);
// registers context load listener
servletContext.addListener(new ContextLoaderListener(webRootContext));
// adds a dispatch servlet, the servlet will be configured from root web app context
ServletRegistration.Dynamic servletConfig = servletContext.addServlet("employee",
new DispatcherServlet(new AnnotationConfigWebApplicationContext()));
servletConfig.setLoadOnStartup(1);