File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
spring-mvc-no-xml/src/main
java/org/baeldung/servlet Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments