2019-10-31 20:43:47 -05:00
|
|
|
package com.baeldung;
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.WebApplicationInitializer;
|
|
|
|
|
import org.springframework.web.context.ContextLoaderListener;
|
|
|
|
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
|
|
|
import org.springframework.web.context.support.GenericWebApplicationContext;
|
|
|
|
|
import org.springframework.web.filter.DelegatingFilterProxy;
|
|
|
|
|
import org.springframework.web.servlet.DispatcherServlet;
|
|
|
|
|
|
2022-02-06 18:31:38 +00:00
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
import javax.servlet.ServletRegistration;
|
|
|
|
|
|
2019-10-31 20:43:47 -05:00
|
|
|
public class AppInitializer implements WebApplicationInitializer {
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-02-06 18:31:38 +00:00
|
|
|
public void onStartup(final ServletContext sc) {
|
2019-10-31 20:43:47 -05:00
|
|
|
|
|
|
|
|
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
|
|
|
|
|
root.scan("com.baeldung");
|
|
|
|
|
sc.addListener(new ContextLoaderListener(root));
|
|
|
|
|
|
|
|
|
|
ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
|
|
|
|
|
appServlet.setLoadOnStartup(1);
|
|
|
|
|
appServlet.addMapping("/");
|
2022-02-06 18:31:38 +00:00
|
|
|
|
2019-10-31 20:43:47 -05:00
|
|
|
sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"))
|
|
|
|
|
.addMappingForUrlPatterns(null, false, "/*");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|