Rest Template


servlet-context.xml 설정



스키마 설정


<beans:beans xmlns="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:util="http://www.springframework.org/schema/util"

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

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">






bean 설정


// RestTemplate bean 등록

<beans:bean id="restTemplate" class="org.springframework.web.client.RestTemplate">

<beans:property name="messageConverters">

<util:list>

<beans:bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

//카멜케이스를 언더스코어로 받기위해 objectMapper 사용

<beans:property name="objectMapper">

<beans:ref bean="objectMapper"/>

</beans:property>

</beans:bean>

<beans:bean class="org.springframework.http.converter.FormHttpMessageConverter">

</beans:bean>

</util:list>

</beans:property>

</beans:bean>


//카멜케이스를 언더 스코어로 해주는 bean 등록

<beans:bean id="objectMapper" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean" autowire="no">

<beans:property name="propertyNamingStrategy" value="CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES" /> 

</beans:bean>


+ Recent posts