<서론>
전 주로 view resolver를 jsp가 아닌 freemarker로 사용합니다.
저 이외에도 freemarker를 jsp 대신 쓰시는 분들이 있을 것 같아
방법을 정리하여 포스팅 합니다.
<본론>
1. 메이븐 dependency를 추가 합니다.
현재 날짜 기준으로 최신 프리마커 버전을 넣어 놓았고, 추후에 메이븐 검색으로
더 높은 버전이 있는지 확인 하신 후 버전업을 해주시면 좋습니다.
1: <!-- freemarker -->
2: <dependency>
3: <groupId>org.freemarker</groupId>
4: <artifactId>freemarker</artifactId>
5: <version>2.3.18</version>
6: </dependency>
2. applicationContext.xml에 기본 View Resolver를 프리마커로 지정하고,
FreeMarkerConfigurer를 추가하여 설정합니다.
(velocity도 이와 매우 흡사한 방법으로 설정 할 수 있습니다.)
1: <?xml version="1.0" encoding="UTF-8"?>
2: <beans xmlns="http://www.springframework.org/schema/beans"
3: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
4: xmlns:context="http://www.springframework.org/schema/context"
5: xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p"
6: xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
7: http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
8: http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
9: http://www.springframework.org/schema/oxm
10: http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">
11:
12: <!-- 다른 설정들이 들어 가겠죠? ^^ -->
13:
14: <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
15: <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
16: <property name="order" value="2" />
17: <property name="cache" value="true" />
18: <property name="suffix" value=".ftl" />
19: <property name="contentType" value="text/html; charset=UTF-8" />
20: <property name="exposeSpringMacroHelpers" value="true" />
21: </bean>
22:
23: <!-- FreeMarker configuration -->
24: <bean id="freemarkerConfig"
25: class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
26: <property name="templateLoaderPath" value="/WEB-INF/freemarker" />
27: <property name="defaultEncoding" value="UTF-8" />
28: </bean>
29: </beans>
<결론>
메이븐 디펜던시 설정 + application context 설정만 하면 프리마커를 사용 할 수 있습니다.