1.1.1. Context Hierarchy
DispatcherServlet expects a WebApplicationContext (an extension of a plain ApplicationContext) for its own configuration. WebApplicationContext has a link to the ServletContext and the Servlet with which it is associated. It is also bound to the ServletContext such that applications can use static methods on RequestContextUtils to look up the WebApplicationContext if they need access to it.
For many applications, having a single WebApplicationContext is simple and suffices. It is also possible to have a context hierarchy where one root WebApplicationContext is shared across multiple DispatcherServlet (or other Servlet) instances, each with its own child WebApplicationContext configuration. See Additional Capabilities of the ApplicationContext for more on the context hierarchy feature.
The root WebApplicationContext typically contains infrastructure beans, such as data repositories and business services that need to be shared across multiple Servlet instances. Those beans are effectively inherited and can be overridden (that is, re-declared) in the Servlet-specific child WebApplicationContext, which typically contains beans local to the given Servlet. The following image shows this relationship:
The following example configures a WebApplicationContext hierarchy:
Reference
'Spring' 카테고리의 다른 글
MVC (Model-View-Controller) 패턴 (0) | 2023.03.29 |
---|---|
Spring MVC프로젝트의 폴더 구조 (0) | 2023.03.28 |
Spring2: root-context.xml (0) | 2022.12.29 |
Spring 1 : web.xml (배포서술자 /Deployment Descriptor) (0) | 2022.12.29 |
Web.xml/ JSP Mapping / contextPath/ contextRoot (0) | 2022.12.21 |