(web.xml)
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
가장 먼저 구동되는 ContextListener 등록 되어 있음
<context-param>에는 root-context.xml 경로 설정
<listener>에는 ContextLoaderListener가 등록
해당 웹 어플리케이션 실행시 같이 동작함
root-context.xml이 처리되면 파일에 있는 Bean 설정들이 동작함
root-context.xml에 정의된 Bean 객체들은 스프링 영역안에 생성되고
객체들간의 의존성이 처리 됨
root-context.xml이 처리된 후에는 SpringMVC에서 사용하는 DispatcherServlet과 관련된 설정이 동작함
(web.xml)
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
DispatcherServlet 클래스는 SpringMVC구조에서 가장 핵심 클래스
웹관련 처리 준비 작업을 할때 사용하는 것이 servlet-context.xml
DispatcherServlet에서 XmlWebApplicationContext를 이용해서 ervlet-context.xml 처리를 시작한다
이 과정에서 만들어진 객체들은 위에서 만들어진 객체들과같이 연동 된다
* SpringMVC 장점
SpringMVC를 이용하게 되면 Servlet/JSP API를 사용할 필요성이 현저히 줄어든다
Spring은 중간에서 연결 역할을 함
따라서 이러한 코드를 작성하지 않아도 기능을 구현 가능하다
'Spring' 카테고리의 다른 글
SpringMVC Controller (0) | 2020.05.21 |
---|---|
MVC , 모델2(Model2) , SpringMVC (0) | 2020.05.21 |
Mybatis - 2 (0) | 2020.05.20 |
Bean (0) | 2020.05.19 |
DI (Dependency Injection) (0) | 2020.05.19 |