diff --git a/spring-mvc-no-xml/src/main/java/org/baeldung/servlet/NewWebApp.java b/spring-mvc-no-xml/src/main/java/org/baeldung/servlet/NewWebApp.java new file mode 100644 index 0000000000..a0181aedaa --- /dev/null +++ b/spring-mvc-no-xml/src/main/java/org/baeldung/servlet/NewWebApp.java @@ -0,0 +1,40 @@ +package org.baeldung.servlet; + +// +//public class NewWebApp extends AbstractAnnotationConfigDispatcherServletInitializer { +// +// public NewWebApp() { +// super(); +// } +// +// // API +// +// @Override +// public void onStartup(final ServletContext servletContext) throws ServletException { +// final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); +// root.setServletContext(servletContext); +// root.scan("org.baeldung.spring"); +// root.refresh(); +// +// final Dynamic servlet = servletContext.addServlet("mvc", new DispatcherServlet(root)); +// servlet.setLoadOnStartup(1); +// servlet.addMapping("/*"); +// } +// +// @Override +// protected Class[] getRootConfigClasses() { +// return null; +// } +// +// @Override +// protected Class[] getServletConfigClasses() { +// return new Class[] { ClientWebConfig.class }; +// } +// +// @Override +// protected String[] getServletMappings() { +// return new String[] { "/*" }; +// } +// +//} + diff --git a/spring-mvc-no-xml/src/main/java/org/baeldung/servlet/WebApp.java b/spring-mvc-no-xml/src/main/java/org/baeldung/servlet/WebApp.java new file mode 100644 index 0000000000..583d083c1c --- /dev/null +++ b/spring-mvc-no-xml/src/main/java/org/baeldung/servlet/WebApp.java @@ -0,0 +1,31 @@ +package org.baeldung.servlet; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration.Dynamic; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class WebApp implements WebApplicationInitializer { + + public WebApp() { + super(); + } + + // API + + @Override + public void onStartup(final ServletContext servletContext) throws ServletException { + final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + root.setServletContext(servletContext); + root.scan("org.baeldung.spring"); + root.refresh(); + + final Dynamic servlet = servletContext.addServlet("mvc", new DispatcherServlet(root)); + servlet.setLoadOnStartup(1); + servlet.addMapping("/"); + } + +} diff --git a/spring-mvc-no-xml/src/main/webapp/WEB-INF/web.xml b/spring-mvc-no-xml/src/main/webapp/WEB-INF/web_old.xml similarity index 100% rename from spring-mvc-no-xml/src/main/webapp/WEB-INF/web.xml rename to spring-mvc-no-xml/src/main/webapp/WEB-INF/web_old.xml