initial work on replacing the web.xml

This commit is contained in:
eugenp 2013-07-26 11:55:43 +03:00
parent c3ef5ed5e4
commit 813295c4d1
3 changed files with 71 additions and 0 deletions

View File

@ -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[] { "/*" };
// }
//
//}

View File

@ -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("/");
}
}