diff --git a/spring-all/src/main/java/com/baeldung/contexts/Greeting.java b/spring-all/src/main/java/com/baeldung/contexts/Greeting.java
new file mode 100644
index 0000000000..99b473c6c4
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/Greeting.java
@@ -0,0 +1,19 @@
+package com.baeldung.contexts;
+
+public class Greeting {
+
+ private String message;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ return "Greeting [message=" + message + "]";
+ }
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java
new file mode 100644
index 0000000000..c3ff90cf39
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java
@@ -0,0 +1,35 @@
+package com.baeldung.contexts.config;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.WebApplicationInitializer;
+import org.springframework.web.context.ContextLoaderListener;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.servlet.DispatcherServlet;
+
+@Configuration
+public class ApplicationInitializer implements WebApplicationInitializer {
+
+ @Override
+ public void onStartup(ServletContext servletContext) throws ServletException {
+ AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
+ rootContext.register(RootApplicationConfig.class);
+ servletContext.addListener(new ContextLoaderListener(rootContext));
+
+ AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext();
+ normalWebAppContext.register(NormalWebAppConfig.class);
+ ServletRegistration.Dynamic normal = servletContext.addServlet("normal-webapp", new DispatcherServlet(normalWebAppContext));
+ normal.setLoadOnStartup(1);
+ normal.addMapping("/api/*");
+
+ AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext();
+ secureWebAppContext.register(SecureWebAppConfig.class);
+ ServletRegistration.Dynamic secure = servletContext.addServlet("secure-webapp", new DispatcherServlet(secureWebAppContext));
+ secure.setLoadOnStartup(1);
+ secure.addMapping("/s/api/*");
+ }
+
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java b/spring-all/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java
new file mode 100644
index 0000000000..c250cedc49
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/NormalWebAppConfig.java
@@ -0,0 +1,25 @@
+package com.baeldung.contexts.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+import org.springframework.web.servlet.view.JstlView;
+
+@Configuration
+@EnableWebMvc
+@ComponentScan(basePackages = { "com.baeldung.contexts.normal" })
+public class NormalWebAppConfig extends WebMvcConfigurerAdapter {
+
+ @Bean
+ public ViewResolver viewResolver() {
+ InternalResourceViewResolver resolver = new InternalResourceViewResolver();
+ resolver.setPrefix("/WEB-INF/view/");
+ resolver.setSuffix(".jsp");
+ resolver.setViewClass(JstlView.class);
+ return resolver;
+ }
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java b/spring-all/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java
new file mode 100644
index 0000000000..59821076d2
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/RootApplicationConfig.java
@@ -0,0 +1,19 @@
+package com.baeldung.contexts.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+import com.baeldung.contexts.Greeting;
+
+@Configuration
+@ComponentScan(basePackages = { "com.baeldung.contexts.services" })
+public class RootApplicationConfig {
+
+ @Bean
+ public Greeting greeting() {
+ Greeting greeting = new Greeting();
+ greeting.setMessage("Hello World !!");
+ return greeting;
+ }
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java b/spring-all/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java
new file mode 100644
index 0000000000..f499a4ceba
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/config/SecureWebAppConfig.java
@@ -0,0 +1,25 @@
+package com.baeldung.contexts.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+import org.springframework.web.servlet.view.JstlView;
+
+@Configuration
+@EnableWebMvc
+@ComponentScan(basePackages = { "com.baeldung.contexts.secure" })
+public class SecureWebAppConfig extends WebMvcConfigurerAdapter {
+
+ @Bean
+ public ViewResolver viewResolver() {
+ InternalResourceViewResolver resolver = new InternalResourceViewResolver();
+ resolver.setPrefix("/WEB-INF/secure/view/");
+ resolver.setSuffix(".jsp");
+ resolver.setViewClass(JstlView.class);
+ return resolver;
+ }
+}
diff --git a/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java b/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java
new file mode 100644
index 0000000000..dd70ce8e97
--- /dev/null
+++ b/spring-all/src/main/java/com/baeldung/contexts/normal/HelloWorldController.java
@@ -0,0 +1,41 @@
+package com.baeldung.contexts.normal;
+
+import java.util.Arrays;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.baeldung.contexts.services.ApplicationContextUtilService;
+import com.baeldung.contexts.services.GreeterService;
+
+@Controller
+public class HelloWorldController {
+
+ @Autowired
+ WebApplicationContext webApplicationContext;
+
+ @Autowired
+ private GreeterService greeterService;
+
+ private void processContext() {
+ WebApplicationContext rootContext = ContextLoader.getCurrentWebApplicationContext();
+
+ System.out.println("root context : " + rootContext);
+ System.out.println("root context Beans: " + Arrays.asList(rootContext.getBeanDefinitionNames()));
+
+ System.out.println("context : " + webApplicationContext);
+ System.out.println("context Beans: " + Arrays.asList(webApplicationContext.getBeanDefinitionNames()));
+ }
+
+ @RequestMapping(path = "/welcome")
+ public ModelAndView helloWorld() {
+ processContext();
+ String message = "