Skip to content

Commit 813295c

Browse files
author
eugenp
committed
initial work on replacing the web.xml
1 parent c3ef5ed commit 813295c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.baeldung.servlet;
2+
3+
//
4+
//public class NewWebApp extends AbstractAnnotationConfigDispatcherServletInitializer {
5+
//
6+
// public NewWebApp() {
7+
// super();
8+
// }
9+
//
10+
// // API
11+
//
12+
// @Override
13+
// public void onStartup(final ServletContext servletContext) throws ServletException {
14+
// final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
15+
// root.setServletContext(servletContext);
16+
// root.scan("org.baeldung.spring");
17+
// root.refresh();
18+
//
19+
// final Dynamic servlet = servletContext.addServlet("mvc", new DispatcherServlet(root));
20+
// servlet.setLoadOnStartup(1);
21+
// servlet.addMapping("/*");
22+
// }
23+
//
24+
// @Override
25+
// protected Class<?>[] getRootConfigClasses() {
26+
// return null;
27+
// }
28+
//
29+
// @Override
30+
// protected Class<?>[] getServletConfigClasses() {
31+
// return new Class<?>[] { ClientWebConfig.class };
32+
// }
33+
//
34+
// @Override
35+
// protected String[] getServletMappings() {
36+
// return new String[] { "/*" };
37+
// }
38+
//
39+
//}
40+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.baeldung.servlet;
2+
3+
import javax.servlet.ServletContext;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.ServletRegistration.Dynamic;
6+
7+
import org.springframework.web.WebApplicationInitializer;
8+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
9+
import org.springframework.web.servlet.DispatcherServlet;
10+
11+
public class WebApp implements WebApplicationInitializer {
12+
13+
public WebApp() {
14+
super();
15+
}
16+
17+
// API
18+
19+
@Override
20+
public void onStartup(final ServletContext servletContext) throws ServletException {
21+
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
22+
root.setServletContext(servletContext);
23+
root.scan("org.baeldung.spring");
24+
root.refresh();
25+
26+
final Dynamic servlet = servletContext.addServlet("mvc", new DispatcherServlet(root));
27+
servlet.setLoadOnStartup(1);
28+
servlet.addMapping("/");
29+
}
30+
31+
}
File renamed without changes.

0 commit comments

Comments
 (0)