Spring Boot应用程序:找不到类型为返回值的转换器 [英] Spring Boot Application: No converter found for return value of type
问题描述
我正在根据这 Spring-Boot写一个简单的REST API
教程.在我的本地开发机(Ubuntu 15.04
和Windows 8.1
)上,所有内容都像超级按钮一样工作.
I am writing a simple REST API
according to this Spring-Boot tutorial. On my local dev machines (Ubuntu 15.04
and Windows 8.1
) everything works like a charm.
我有一台旧的32-bit
Ubuntu 12.04 LTS
服务器,我想在其上部署REST
服务.
I have an old 32-bit
Ubuntu 12.04 LTS
server lying around on which I wanted to deploy my REST
service.
启动日志没问题,但是一旦我向/user/{id}
端点发送GET
请求,就会收到以下错误:
The starting log is ok, but as soon as I send a GET
request to the /user/{id}
endpoint, I get the following error:
java.lang.IllegalArgumentException: No converter found for return value of type: class ch.gmazlami.gifty.models.user.User
然后沿着堆栈跟踪:
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.LinkedHashMap
整个堆栈跟踪记录发布在此处.
The entire stacktrace is posted here.
我调查了一些有关此错误的答案,但是由于我使用的是Spring-Boot,因此这些答案似乎不适用于我的问题.
I looked into some answers referring this error, but those don't seem to apply to my problem, since I'm using Spring-Boot, no xml
configs whatsoever.
受影响的控制器是:
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
public ResponseEntity<User> getUser(@PathVariable Long id){
try{
return new ResponseEntity<User>(userService.getUserById(id), HttpStatus.OK);
}catch(NoSuchUserException e){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
任何帮助将不胜感激.这很奇怪,因为完全相同的东西在其他机器上也能很好地工作.
Any help would be greatly appreciated. It is very weird since the exact same things work on other machines perfectly.
推荐答案
您应该对pom.xml和mvc-dispatcher-servlet.xml文件进行一些更改: 将以下依赖项添加到pom.xml中:
you should make some changes to your pom.xml and mvc-dispatcher-servlet.xml files: Add the following dependecies to your pom.xml :
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
并更新您的mvc-dispatcher-servlet.xml:
and update your mvc-dispatcher-servlet.xml:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
这篇关于Spring Boot应用程序:找不到类型为返回值的转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!