package app.config;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.annotation.WebListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
@WebListener
public class SpringConfigurationInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
final ServletContext ctx = sce.getServletContext();
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.setServletContext(ctx);
root.scan("app");
root.refresh();
final Dynamic servlet = ctx.addServlet("spring", new DispatcherServlet(root));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}