【发布时间】:2014-08-21 12:01:57
【问题描述】:
我在 Spring MVC 控制器中有一个简单的 REST 方法,如下所示,其签名为:
@RequestMapping(value="/person/{personId}", method=RequestMethod.GET) 公共 @ResponseBody 对象 getPerson(@PathVariable("personId") String personId) {
... }
输出类型为Object,因为此方法返回了几种不同的数据类型。
从 Spring MVC 应用程序中的测试程序调用时,如下所示:
private static void getPerson() {
logger.info(Rest.class.getName() + ".getPerson() method called.");
RestTemplate restTemplate = new RestTemplate();
Person person = restTemplate.getForObject("http://localhost:8080/Library/rest/person/1", Person.class);
ObjectMapper responseMapper = new ObjectMapper();
...
}
响应为Content type 'null' not supported,调用失败。
谁能告诉我为什么?
当从另一个不使用 Spring 但发出 HTTP GET 请求的应用程序中的测试程序调用时,控制器方法被正确调用并工作。
【问题讨论】:
标签: java rest http spring-mvc