web.xml
개요
Web Application의 환경설정 파일로 Web Application에 단 하나만 존재한다. 서버는 처음 로딩될 때 web.xml파일을 읽고 해당 환경 설정을 tomcat에 적용시켜 서버를 실행한다. Spring legacy project에 webapp/WEB-INF 경로에 위치한다.
구조
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<!-- context-param을 통해 root-context.xml과 연결 정보를 설정한다. -->
<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>
<!-- Processes application requests -->
<!-- servlet을 통해 servlet-context.xml과 연결 정보를 설정한다. -->
<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>
<!-- post incoding -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
context-param 태그에서 root-context.xml과의 연결 정보를 설정한다.
servlet 태그에서 servlet-context.xml과의 연결 정보를 설정한다.
root-context.xml
비즈니스 로직과 관련 있는 db에 접속하기 위한 정보, sqlSession 등에 대한 정보 등이 기재되어 있다.
servlet-context.xml
요청과 관련 있는 view에 대한 정보들이 기재되어 있다.
'이론정리' 카테고리의 다른 글
Mapper란? (0) | 2020.11.15 |
---|---|
JUnit이란 (0) | 2020.11.15 |
pom.xml(Project Option Model)이란 (0) | 2020.11.15 |