🚂 Spring 파일들의 실행 순서
web.xml 👉🏻 root-context.xml 👉🏻 servlet-context.xml
web.xml
배포 서술자라고 부르는 파일, 서버가 구동될 때 가장 먼저 읽혀지는 파일
즉, 복잡한 스프링 환경설정 파일들 중에 가장 먼저 읽혀지는 파일
👉🏻 서버가 알아야 할 가장 기본적인 설정은 이 파일에 다 기술되어 있어야만 함
web.xml 구조
1) 파일 정의 영역
👉🏻 xsi: 유효성 검사를 해 주면서 해당 파일이 xml 파일이 맞음을 인증해 줌
2) The definition of the Root Spring Container shared by all Servlets and Filters
👉🏻 스프링의 최상위 설정 파일(root-context.xml) 의 경로를 지정한 부분
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<!-- 스프링의 최상위 설정 파일(root-context.xml) 의 경로를 지정한 부분 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
3) Creates the Spring Container shared by all Servlets and Filters
👉🏻 모든 설정 파일을 연결할 수 있는 도구 (== bean == 자바 객체) 를 등록한 부분
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<!-- 모든 설정 파일을 연결할 수 있는 도구 (== bean == 자바 객체) 를 등록한 부분 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
4) Processes application requests
👉🏻 웹 사이트의 요청 처리를 어떻게 할 건지 등록한 부분
즉, 요청을 처리하는 메인 서블릿을 등록한 부분(무조건 있어야 하는 설정)
👉🏻 해당 서블릿명: DispatcherServlet
✔️ 스프링에서는 내가 직접 서블릿을 만들 필요가 없음
알게 모르게 스프링 내부에서는 중앙 처리 요청을 해 주는 서블릿이 존재함
모든 요청은 그 중앙 처리 요청을 해 주는 서블릿을 거쳐가기 마련임
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- DispatcherServlet 과 관련된 추가 설정에 대한 내용을 등록한 부분 -->
<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> <!-- DispatcherServlet이 읽어들여야 할 파일의 우선순위가 1순위 -->
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
👉🏻 모든 요청을 DispatcherServlet으로 가게 하겠다
기존의 코드 흐름
Spring에서의 코드 흐름
👉🏻 왕천재 DispatcherServlet이 view와 controller 사이에서 열일 함 (자기가 알아서 원하는 곳으로 보내 줌)
👉🏻 contoller에서 jsp를 지정할 필요가 없어지므로 해당 코드가 확 줄어듦!
👉🏻 스프링에서 제일 중요