11package com .baeldung .contexts .config ;
22
3- import org .springframework .web .context .AbstractContextLoaderInitializer ;
43import org .springframework .web .context .WebApplicationContext ;
54import org .springframework .web .context .support .AnnotationConfigWebApplicationContext ;
65import org .springframework .web .servlet .support .AbstractDispatcherServletInitializer ;
@@ -9,20 +8,29 @@ public class AnnotationsBasedApplicationAndServletInitializer extends AbstractDi
98
109 @ Override
1110 protected WebApplicationContext createRootApplicationContext () {
12- AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext ();
13- rootContext .register (RootApplicationConfig .class );
14- return rootContext ;
11+ //If this is not the only class declaring a root context, we return null because it would clash
12+ //with other classes, as there can only be a single root context.
13+
14+ //AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
15+ //rootContext.register(RootApplicationConfig.class);
16+ //return rootContext;
17+ return null ;
1518 }
1619
1720 @ Override
1821 protected WebApplicationContext createServletApplicationContext () {
19- AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext ();
20- secureWebAppContext .register (SecureWebAppConfig .class );
21- return secureWebAppContext ;
22+ AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext ();
23+ normalWebAppContext .register (NormalWebAppConfig .class );
24+ return normalWebAppContext ;
2225 }
2326
2427 @ Override
2528 protected String [] getServletMappings () {
26- return new String [] { "/s/api/*" };
29+ return new String [] { "/api/*" };
30+ }
31+
32+ @ Override
33+ protected String getServletName () {
34+ return "normal-dispatcher" ;
2735 }
2836}
0 commit comments