|
| 1 | +package com.baeldung.spring.dispatcher.servlet; |
| 2 | + |
| 3 | +import org.springframework.web.context.ContextLoaderListener; |
| 4 | +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; |
| 5 | +import org.springframework.web.servlet.DispatcherServlet; |
| 6 | + |
| 7 | +import javax.servlet.MultipartConfigElement; |
| 8 | +import javax.servlet.ServletContext; |
| 9 | +import javax.servlet.ServletException; |
| 10 | +import javax.servlet.ServletRegistration; |
| 11 | + |
| 12 | +public class WebApplicationInitializer implements org.springframework.web.WebApplicationInitializer { |
| 13 | + @Override |
| 14 | + public void onStartup(ServletContext servletContext) throws ServletException { |
| 15 | + AnnotationConfigWebApplicationContext rootContext = |
| 16 | + new AnnotationConfigWebApplicationContext(); |
| 17 | + rootContext.register(RootConfiguration.class); |
| 18 | + servletContext.addListener(new ContextLoaderListener(rootContext)); |
| 19 | + AnnotationConfigWebApplicationContext webContext = |
| 20 | + new AnnotationConfigWebApplicationContext(); |
| 21 | + webContext.register(WebConfiguration.class); |
| 22 | + webContext.scan("com.baeldung.spring.dispatcher.servlet.web"); |
| 23 | + ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", |
| 24 | + new DispatcherServlet(webContext)); |
| 25 | + servlet.addMapping("/*"); |
| 26 | + MultipartConfigElement multipartConfigElement = |
| 27 | + new MultipartConfigElement("/tmp"); |
| 28 | + servlet.setMultipartConfig(multipartConfigElement); |
| 29 | + } |
| 30 | +} |
0 commit comments