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.

WebApplication에 대한 설명이 드디어 나온다…

DispatcherServlet은 WebApplicationContext를 요구한다. WebApplicationContext는 기존에 우리가 스프링 웹을 사용하지 않고, DI만 이용할때 생성하던 ApplicationContext의 확장판 인터페이스이다.

WebApplicationContext는 ServletContext와 이와 연관된 Servlet들에 대한 link를 갖고 있다.

또한 WebApplicationContext는 스스로 ServletContext에 바인딩되기도 한다. 이를 통해 Application이 WebApplicationContext에 접근하고 싶을때, RequestContextUtils라는 객체의 스태틱 메서드를 통해 접근할 수 있도록 만든다…

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.

대부분의 어플리케이션에서는 하나의 WebApplicationContext를 갖는 것이 간단하고 또 충분하다. 하나만 가지면 context의 계층도, 오직 하나의 WebApplciationContext를 루트로 해, 이를 공유하는 여러개의 DispatcherServlet, 혹은 Servlet객체를 만들 수도 있다.또한 각각의 DispatcherServlet, Servlet객체들이 그들만의 WebApplciationContext config를 가질수도 있다…!!!

사실 하나의 앱이 하나의 WebApplicationContext 인터페이스를 갖되, 앱 내의 여러개의 DispatcherServlet이 초기화되고 생성될때 각자의 WebApplicationContext설정을 갖고 구성될 수 있다는 의미인듯…

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:

루트 WebApplicationContext는 인프라 빈들을 갖는다… 서비스나 리포지 같은거.. 이건 여러개의 서블릿객체들 사이에서 공유되어야 하는 것들임. 그리고 이런 서비스, 리포지 빈들은 같은 루트 WebApp을 공유하는 서블릿들이 자신만의 WebApp을 설정을 가져 오버라이드 할 수도 있다.

Untitled