Spring 3 추가 지원요소

Spring 3.0을 테스트해보면서 몇가지 눈에 띄는 새로운 지원요소들을 정리해 보았다.

1. Spring MVC REST

@RequestMapping, @PathVariable Annotation을 통한 RESTful 스타일의 URL Mapping.

예)

@RequestMapping(method = RequestMethod.GET, value = "/ws/list/{key}", headers = "Accept=application/json")
public ModelAndView getUserList(@PathVariable String key) { ... }

2. Content Negotiating

HTTP Accept Header로 클라이언트에 응답할 View를 결정. (ContentNegotiatingViewResolver 이용)

3. HttpMessageConverter

HttpMessageConverter, @ResponseBody를 통한 응답.

Converter Media Type
StringHttpMessageConverter text/* (read) -> text/plain (write)
FormHttpMessageConverter application/x-www-form-urlencoded (read) -> MultiValueMap<String, String> (write)
MarshallingHttpMessageConverter application/xml (read/write)
MappingJacksonHttpMessageConverter application/json (read/write)
AtomFeedHttpMessageConverter application/atom+xml (read/write)
RssChannelHttpMessageConverter application/rss+xml (read/write)

예) json 형식으로 메세지 타입 자동 변환 Converter 등록. (MappingJacksonHttpMessageConverter)

[applicationContext.xml]
...
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes" value="application/json" />
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jsonConverter" />
        </list>
    </property>
</bean>
...

예) @RequestBody를 통한 응답데이터 타입 자동 변환.

@RequestMapping(value = "/ws/list/{key}", headers = "Accept=application/json")
public @ResponseBody TestVO getUserList(@PathVariable String key) { return testService.getUserList(key); }

4. RestTemplate

REST Client Utility.

RestTemplate.exchange(…)
RestTemplate.getForObject(…)
RestTemplate.postForObject(…)
RestTemplate.put(…)
RestTemplate.delete(…)

5. HTTP Method Conversion

HiddenHttpMethodFilter를 통해 POST/GET 이외의 HTTP Method 요청.

예) Filter 등록.

[web.xml]
...
<filter>
    <filter-name>httpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>httpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</filter>
...

예) jsp

<form:form action="/ws/del/aa1" method="delete"> ... </form:form>

6. ETag

ShallowEtagHeaderFilter를 통해 요청된 URL의 내용 변경여부 확인.
MD5 Hash값을 비교하는 Shallow Tag 방법으로 내용의 변경이 없을 경우, 304 응답코드를 반환한다.

7. 기타 View

MarshallingView, JacksonJsonView, AbstractAtomFeedView, AbstractRssFeedView 추가.

Tags:

Updated:

Comments