| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.config;
|
1 |
package com.spice.profitmandi.web.config;
|
| 2 |
|
2 |
|
| - |
|
3 |
import javax.servlet.FilterRegistration;
|
| 3 |
import javax.servlet.ServletContext;
|
4 |
import javax.servlet.ServletContext;
|
| 4 |
|
5 |
|
| 5 |
import javax.servlet.ServletException;
|
6 |
import javax.servlet.ServletException;
|
| 6 |
import javax.servlet.ServletRegistration;
|
7 |
import javax.servlet.ServletRegistration;
|
| 7 |
|
8 |
|
| Line 11... |
Line 12... |
| 11 |
import org.springframework.web.context.ContextLoaderListener;
|
12 |
import org.springframework.web.context.ContextLoaderListener;
|
| 12 |
import org.springframework.web.context.WebApplicationContext;
|
13 |
import org.springframework.web.context.WebApplicationContext;
|
| 13 |
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
14 |
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
| 14 |
import org.springframework.web.servlet.DispatcherServlet;
|
15 |
import org.springframework.web.servlet.DispatcherServlet;
|
| 15 |
|
16 |
|
| - |
|
17 |
import com.spice.profitmandi.common.web.filter.CorsFilter;
|
| - |
|
18 |
|
| 16 |
public class SpringWebAppInitializer implements WebApplicationInitializer{
|
19 |
public class SpringWebAppInitializer implements WebApplicationInitializer{
|
| 17 |
|
20 |
|
| 18 |
private static final Logger LOGGER=LogManager.getLogger(SpringWebAppInitializer.class);
|
21 |
private static final Logger LOGGER=LogManager.getLogger(SpringWebAppInitializer.class);
|
| 19 |
|
22 |
|
| 20 |
private static final String DISPATCHER_SERVLET_NAME="DispatcherServlet";
|
23 |
private static final String DISPATCHER_SERVLET_NAME="DispatcherServlet";
|
| Line 24... |
Line 27... |
| 24 |
WebApplicationContext context = getContext();
|
27 |
WebApplicationContext context = getContext();
|
| 25 |
servletContext.addListener(new ContextLoaderListener(context));
|
28 |
servletContext.addListener(new ContextLoaderListener(context));
|
| 26 |
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(context));
|
29 |
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(context));
|
| 27 |
dispatcher.setLoadOnStartup(1);
|
30 |
dispatcher.setLoadOnStartup(1);
|
| 28 |
dispatcher.addMapping("/");
|
31 |
dispatcher.addMapping("/");
|
| - |
|
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 |
|
| 29 |
LOGGER.info("Context is loaded");
|
37 |
LOGGER.info("Context is loaded");
|
| 30 |
}
|
38 |
}
|
| 31 |
|
39 |
|
| 32 |
private AnnotationConfigWebApplicationContext getContext() {
|
40 |
private AnnotationConfigWebApplicationContext getContext() {
|
| 33 |
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
41 |
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|