Spring Boot 应用程序:找不到类型返回值的转换器 [英] Spring Boot Application: No converter found for return value of type

查看:25
本文介绍了Spring Boot 应用程序:找不到类型返回值的转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据this<编写一个简单的REST API/a> Spring-Boot 教程.在我的本地开发机器(Ubuntu 15.04Windows 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 位 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

整个堆栈跟踪发布在这里.

我查看了一些提到此错误的答案,但这些答案似乎不适用于我的问题,因为我使用的是 Spring-Boot,没有任何 xml 配置.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆