| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 35385 |
amit |
3 |
import javax.servlet.FilterRegistration;
|
| 21165 |
ashik.ali |
4 |
import javax.servlet.ServletContext;
|
|
|
5 |
|
|
|
6 |
import javax.servlet.ServletException;
|
|
|
7 |
import javax.servlet.ServletRegistration;
|
|
|
8 |
|
| 23568 |
govind |
9 |
import org.apache.logging.log4j.Logger;
|
|
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 21165 |
ashik.ali |
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 |
|
| 35385 |
amit |
17 |
import com.spice.profitmandi.common.web.filter.CorsFilter;
|
|
|
18 |
|
| 21165 |
ashik.ali |
19 |
public class SpringWebAppInitializer implements WebApplicationInitializer{
|
|
|
20 |
|
| 23568 |
govind |
21 |
private static final Logger LOGGER=LogManager.getLogger(SpringWebAppInitializer.class);
|
| 21165 |
ashik.ali |
22 |
|
|
|
23 |
private static final String DISPATCHER_SERVLET_NAME="DispatcherServlet";
|
| 21220 |
ashik.ali |
24 |
private static final String SPRING_CONFIG_PACKAGE_LOCATION="com.spice.profitmandi.web.config";
|
| 21165 |
ashik.ali |
25 |
|
|
|
26 |
public void onStartup(ServletContext servletContext) throws ServletException {
|
|
|
27 |
WebApplicationContext context = getContext();
|
|
|
28 |
servletContext.addListener(new ContextLoaderListener(context));
|
|
|
29 |
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(context));
|
|
|
30 |
dispatcher.setLoadOnStartup(1);
|
|
|
31 |
dispatcher.addMapping("/");
|
| 35385 |
amit |
32 |
|
|
|
33 |
// Register CORS filter to handle CORS for all requests including error responses
|
|
|
34 |
FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", new CorsFilter());
|
|
|
35 |
corsFilter.addMappingForUrlPatterns(null, false, "/*");
|
|
|
36 |
|
| 21165 |
ashik.ali |
37 |
LOGGER.info("Context is loaded");
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
private AnnotationConfigWebApplicationContext getContext() {
|
|
|
41 |
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
|
|
42 |
context.setConfigLocation(SPRING_CONFIG_PACKAGE_LOCATION);
|
|
|
43 |
return context;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
}
|