/** * */ package org.ec.app.main; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import org.apache.log4j.Logger; import org.ec.app.config.AppConfig; import org.ec.app.config.constants.IConfigConstants; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; /** * @author arpan * */ public class AppInitializer implements WebApplicationInitializer{ private static final Logger log = Logger.getLogger(AppInitializer.class); @Override public void onStartup(ServletContext servletContext) throws ServletException { log.info("onStartup() method invoked"); WebApplicationContext webContext = getContext(); servletContext.addListener(new ContextLoaderListener(webContext)); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(webContext)); dispatcher.setLoadOnStartup(IConfigConstants.LOAD_ON_STARTUP_VALUE); dispatcher.addMapping(IConfigConstants.MAPPING_URL); } private AnnotationConfigWebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(AppConfig.class); return context; } }