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