WebApplicationContext is a specialized Spring ApplicationContext for web applications, extending the standard container with web-specific scopes and access to the ServletContext. It's what DispatcherServlet uses to look up controllers, view resolvers, and other web-tier beans.
Key Points: • It adds request and session bean scopes on top of the standard singleton and prototype scopes. • DispatcherServlet has its own WebApplicationContext for web-layer beans (controllers, view resolvers), separate from a parent context that typically holds services and repositories. • The parent-child context hierarchy means beans defined in the root context are visible to the DispatcherServlet's child context, but not the other way around. • It's accessible from JSPs and other web artifacts via WebApplicationContextUtils when needed outside of dependency injection. • Spring Boot typically flattens this into a single application context for simplicity, though the same WebApplicationContext type still underlies it.
Example: In a traditional multi-module Spring MVC app, the root context loads service and repository beans shared across the whole application, while the DispatcherServlet's WebApplicationContext loads just the controllers and view resolvers needed for the web tier.
Interview Tip: A concise interview answer is:
"WebApplicationContext is Spring's web-aware ApplicationContext, adding request and session bean scopes and ServletContext access on top of the standard container. DispatcherServlet uses it to locate and wire up controllers and view resolvers, and in traditional apps it often sits as a child context beneath a root context holding services and repositories."