티스토리 뷰

서블릿 컨테이너는 서블릿의 생명주기를 관리한다. 서블릿 컨테이너 내부에는 여러개의 서블릿이 존재 하는데, 서블릿의 집합이 하나의 웹 앱을 만든다. Application Context란 여러개의 웹 앱들이 공유하는 환경을 의미한다. 따라서 이곳에, Dao와 관련된 빈이나 서비스 로직에 관련된 빈을 모두 모아놓으면 된다. 왜냐면 이러한 빈들은 여러 앱들에서 공유 될 수 있기 때문이다. 즉 root application context이다.


Servlet Application Context == Web Application Context이다. 각 앱 내부에 하나씩 존재한다. 즉, 웹앱컨텍스트는 하나의 서블릿 컨테이너 내부에서 여러개가 존재 할 수 있다. 


2.3 Difference between the two contexts

So the best part of this article, is what’s the difference between the two contexts?

Firstly, as already mentioned, ApplicationContext is the root-context, that has bean configurations we might want to use (and re-use) across the entire application as singletons. There is always a single application context in a web application. Whereas, there can be multiple WebApplicationContexts for each of the dispatcher servlets we specify in our application’s web.xml.

WebApplicationContext internally extends ApplicationContext, and as a child inherits all the beans from its parent. So we can also override the parent bean within our WebApplicationContext.

It’s always better to keep a clear separation between middle-tier services such as business logic components and data access classes (which we prefer defining in the ApplicationContext XML), and web-related components such as controllers and view-resolvers (which we prefer defining in the respective dispatcher-servlet‘s WebApplicationContext).

Configuring contextLoaderListener is completely optional. We can boot up a Spring application with just the dispatcher-servlet, without even configuring contextLoaderListener (that loads up the root-context).

'컴퓨터 공학과 졸업 > 기본 개념' 카테고리의 다른 글

Mybatis 구조  (2) 2018.08.17
[퍼옴]도메인이란  (0) 2018.08.03
웹 프로그램의 파일 구조  (0) 2018.07.27
MIME TYPE  (0) 2018.07.26
HTTP  (0) 2018.06.28
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함