1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.audit.service.config;
18
19 import org.apache.logging.log4j.catalog.api.util.ProfileUtil;
20 import org.springframework.web.WebApplicationInitializer;
21 import org.springframework.web.context.ContextLoaderListener;
22 import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
23 import org.springframework.web.servlet.DispatcherServlet;
24
25 import javax.servlet.ServletContext;
26 import javax.servlet.ServletException;
27 import javax.servlet.ServletRegistration;
28
29 public class WebAppInitializer implements WebApplicationInitializer {
30 private static final String APPLICATION_NAME = "AuditService";
31
32 @Override
33 public void onStartup(ServletContext servletContext) throws ServletException {
34 servletContext.setInitParameter("applicationName", APPLICATION_NAME);
35 System.setProperty("applicationName", APPLICATION_NAME);
36 ProfileUtil.setActiveProfile(servletContext);
37 AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
38 rootContext.setDisplayName(APPLICATION_NAME);
39 rootContext.register(ApplicationConfiguration.class);
40 servletContext.addListener(new ContextLoaderListener(rootContext));
41
42
43 AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
44 mvcContext.register(WebMvcAppContext.class);
45
46 ServletRegistration.Dynamic restServlet = servletContext.addServlet("restServlet", new DispatcherServlet(mvcContext));
47 restServlet.setLoadOnStartup(1);
48 restServlet.addMapping("/*");
49 }
50
51
52
53 }