Subversion Repositories SmartDukaan

Rev

Rev 23568 | Rev 23628 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21561 ashik.ali 1
package com.spice.profitmandi.web.config;
21555 kshitij.so 2
 
3
import javax.servlet.ServletContext;
4
import javax.servlet.ServletException;
5
import javax.servlet.ServletRegistration;
6
 
23575 ashik.ali 7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.springframework.context.ApplicationContext;
10
import org.springframework.context.annotation.Bean;
21555 kshitij.so 11
import org.springframework.web.WebApplicationInitializer;
12
import org.springframework.web.context.ContextLoaderListener;
13
import org.springframework.web.context.WebApplicationContext;
14
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
15
import org.springframework.web.servlet.DispatcherServlet;
16
 
17
public class SpringWebAppInitializer implements WebApplicationInitializer{
18
 
23575 ashik.ali 19
	private static final Logger LOGGER=LoggerFactory.getLogger(SpringWebAppInitializer.class);
21555 kshitij.so 20
 
21
	private static final String DISPATCHER_SERVLET_NAME="DispatcherServlet";
21568 ashik.ali 22
	private static final String SPRING_CONFIG_PACKAGE_LOCATION="com.spice.profitmandi.web.config";
21555 kshitij.so 23
 
23575 ashik.ali 24
	private ApplicationContext applicationContext;
25
 
21555 kshitij.so 26
	public void onStartup(ServletContext servletContext) throws ServletException {
27
		WebApplicationContext context = getContext();
23575 ashik.ali 28
		applicationContext = context;
21555 kshitij.so 29
        servletContext.addListener(new ContextLoaderListener(context));
30
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(context));
31
        dispatcher.setLoadOnStartup(1);
32
        dispatcher.addMapping("/");
33
        LOGGER.info("Context is loaded");
34
	}
35
 
36
	private AnnotationConfigWebApplicationContext getContext() {
37
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
38
        context.setConfigLocation(SPRING_CONFIG_PACKAGE_LOCATION);
39
        return context;
40
    }
41
 
23575 ashik.ali 42
	@Bean(name="applicationContext")
43
	public ApplicationContext getApplicationContext() {
44
		return applicationContext;
45
	}
21555 kshitij.so 46
 
47
}