Rev 23575 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.config;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletRegistration;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.Bean;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;public class SpringWebAppInitializer implements WebApplicationInitializer{private static final Logger LOGGER = LogManager.getLogger(SpringWebAppInitializer.class);private static final String DISPATCHER_SERVLET_NAME="DispatcherServlet";private static final String SPRING_CONFIG_PACKAGE_LOCATION="com.spice.profitmandi.web.config";private ApplicationContext applicationContext;public void onStartup(ServletContext servletContext) throws ServletException {WebApplicationContext context = getContext();applicationContext = context;servletContext.addListener(new ContextLoaderListener(context));ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(context));dispatcher.setLoadOnStartup(1);dispatcher.addMapping("/");LOGGER.info("Context is loaded");}private AnnotationConfigWebApplicationContext getContext() {AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();context.setConfigLocation(SPRING_CONFIG_PACKAGE_LOCATION);return context;}@Bean(name="applicationContext")public ApplicationContext getApplicationContext() {return applicationContext;}}