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