<mvc:annotation-driven />
▶ 어노테이션을 사용할 수 있게 해주는 설정
(@Controller, @RequestMapping, @ResponseBody, @Valid)
<mvc:resources mapping="/resources/**" location="/resources/" />
▶ "/resources/"아래의 모든 파일을 직접적으로 요청이 가능하다.
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<!-- TilesConfigurer는 Tiles 관련 설정을 로드하고 사용하도록 도와줌. -->
<property name="definitions">
<!-- definitions : Tiles XML 설정 파일을 지정 -->
<list>
<value>classpath:tiles/*.xml</value>
</list>
</property>
<property name="preparerFactoryClass" value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />
<!-- SpringBeanPreparerFactory : Tiles에서 Spring의 Bean을 활용 가능 -->
</bean>
▶ Tiles를 사용하면 JSP의 공통 레이아웃을 효율적으로 관리할 수 있다.
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
▶ UrlBasedViewResolver : JSP 파일이 아닌 Tiles 템플릿(XML 설정 파일)을 기반으로 뷰를 찾는다.
▶ TilesView : Tiles 레이아웃을 사용하기 위한 전용 뷰 리졸버(View Resolver)
이게 없으면 Tiles가 작동하지 않는다! 🚀
<context:component-scan base-package="com.test.pro14" />
▶ context:component-scan :
@Component , @Service , @Repository , @Controller 등의 어노테이션이 붙은 클래스를 자동으로 Bean으로 등록하도록 하는 설정이다.
<mvc:interceptors>
▶interceptors :
컨트롤러(Controller) 실행 전/후에 특정 작업을 수행하는 기능, 컨트롤러 요청만 가로챈다.
✅ mvc:interceptors → 컨트롤러 실행 전후로 특정 기능을 수행하는 인터셉터를 설정
✅ preHandle() → 컨트롤러 실행 전에 수행된다. (로그인 체크 등)
✅ postHandle() → 컨트롤러 실행 후, 뷰 렌더링 전에 수행된다.
✅ afterCompletion() → 뷰 렌더링 후 실행된다. (예외 처리 등)
✅ 로그 기록, 권한 검사, 인증 체크, 공통 데이터 설정 등에 유용하다. 🚀
<mvc:mapping path="/*/*.do"/>
<bean class="com.test.pro14.common.interceptor.ViewNameInterceptor" />
<!-- 실제로 동작할 인터셉터 클래스 (ViewNameInterceptor)를 등록.
com.test.pro14.common.interceptor 패키지 안에 ViewNameInterceptor 클래스가 존재해야 함. -->
▶ mvc:mapping path="/*/*.do" :
/*.do 패턴을 가지는 모든 요청(URL)이 해당 인터셉터를 거치도록 설정.
(/member/login.do, /board/list.do) 같은 요청
파일 업로드를 처리하기 위한 설정
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="52428800" />
<property name="maxInMemorySize" value="1000000" />
<property name="defaultEncoding" value="utf-8" />
</bean>
▶ CommonsMultipartResolver :
파일을 업로드할 때 크기 제한, 인코딩 등을 설정할 수 있다.