스프링 설정 파일 중 봐야 할 것들,
- servlet-context.xml
- root-context.xml
- web.xml
- pom.xml
이다.
- web.xml 은 서버에서 시작지점이 된다고 보면 된다
- servlet-context.xml은서블릿 영역의 설정을 해주는 부분으로 A라는 관리자 서블릿과 b라는 사용자 서블릿이 있을 때 서로의 접근을 차단해주어야 하지만, DB는 공유해야 하기 때문에 서블릿을 A,B로 구분하고 root-context.xml에서 공용으로 사용하는 DB를 설정해 주는것
- pom.xml 은 메이븐 관리해주는 곳...(여긴 잘 모르겠음)
- root-context.ml 은 프로젝트 의 영역을 설정
[web.xml]
<?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 http://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>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
root context로 모든 서블릿과 필터들이 공유한다고 함.
<!-- 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-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>
서블릿에 대한 url 패턴을 정의
<!-- encoding setting start-->
<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> <!-- root 하위 모든 요청에 인코딩을 처리하겠단 의미 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- encoding setting end-->
<!-- encoding setting start-->
<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> <!-- root 하위 모든 요청에 인코딩을 처리하겠단 의미 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- encoding setting end-->
</web-app>
[servlet-context.xml]
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven /> 어노테이션을 사용하겠다는 선언
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" /> 리소스 정의
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.myhome.lnk" />
com.myhome.lnk 아래의 모든 패키지에 있는 파일의 어노테이션을 빈으로 등록해 사용하겠다는 말.(중요)
</beans:beans>
댓글 없음:
댓글 쓰기