diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index bb983b43e6..45551f7242 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -120,7 +120,7 @@ - 3.2.2.RELEASE + 3.2.3.RELEASE 1.7.5 @@ -132,7 +132,7 @@ 1.9.5 4.2.4 - 4.2.4 + 4.2.5 1.8.0 1.8.9 diff --git a/spring-mvc-java/src/main/java/org/baeldung/spring/web/config/MainWebAppInitializer.java b/spring-mvc-java/src/main/java/org/baeldung/spring/web/config/MainWebAppInitializer.java new file mode 100644 index 0000000000..81a94f1a8c --- /dev/null +++ b/spring-mvc-java/src/main/java/org/baeldung/spring/web/config/MainWebAppInitializer.java @@ -0,0 +1,41 @@ +package org.baeldung.spring.web.config; + +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +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.servlet.DispatcherServlet; + +public class MainWebAppInitializer implements WebApplicationInitializer { + + /** + * Register and configure all Servlet container components necessary to power the web application. + */ + @Override + public void onStartup(final ServletContext sc) throws ServletException { + System.out.println("GreenhouseWebAppInitializer.onStartup()"); + + // Create the 'root' Spring application context + final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + root.scan("org.baeldung.spring.web.config"); + // root.getEnvironment().setDefaultProfiles("embedded"); + + // Manages the lifecycle of the root application context + sc.addListener(new ContextLoaderListener(root)); + + // Handles requests into the application + final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext())); + appServlet.setLoadOnStartup(1); + final Set mappingConflicts = appServlet.addMapping("/"); + if (!mappingConflicts.isEmpty()) { + throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278"); + } + } + +} diff --git a/spring-mvc-java/src/main/webapp/WEB-INF/web.xml b/spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml similarity index 100% rename from spring-mvc-java/src/main/webapp/WEB-INF/web.xml rename to spring-mvc-java/src/main/webapp/WEB-INF/web_old.xml