`
TRAMP_ZZY
  • 浏览: 137788 次
社区版块
存档分类
最新评论

Spring4 RestTemplate :no suitable httpmessageconverter found for response type

阅读更多
 <bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
        <property name="messageConverters">
            <list>
                <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
                <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
                <bean id="formHttpMessageConverter" class="org.springframework.http.converter.FormHttpMessageConverter"/>
            </list>
        </property>
    </bean>


public class ClientDeviceControllerTests {
    private String url = "http://localhost:8080/servicemanager/service/order/list";

    @Test
    public void testAppInstall() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/rmi-client.xml");
        RestTemplate template = applicationContext.getBean("restTemplate", RestTemplate.class);
        MessageDto messageDto = template.getForObject(url, MessageDto.class);

        System.out.println(messageDto);
        RestTemplate temp = new RestTemplate();
        temp.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        temp.getMessageConverters().add(new StringHttpMessageConverter());
        temp.getMessageConverters().add(new FormHttpMessageConverter());
        MessageDto messageDto2 = temp.getForObject(url, MessageDto.class);

        System.out.println(messageDto2);
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics