gpt4 book ai didi

rest - Spring Boot 应用程序 : No converter found for return value of type

转载 作者:太空宇宙 更新时间:2023-11-03 16:42:26 24 4
gpt4 key购买 nike

我正在根据 this 编写一个简单的 REST API Spring-Boot 教程。在我的本地开发机器(Ubuntu 15.04Windows 8.1)上,一切正常。

我有一个旧的 32 位 Ubuntu 12.04 LTS 服务器,我想在其上部署我的 REST 服务。

启动日志没问题,但是一旦我向 /user/{id} 端点发送 GET 请求,我就会收到以下错误:

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

整个堆栈跟踪已发布 here .

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

受影响的 Controller 是:

    @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);
}
}

如有任何帮助,我们将不胜感激。这很奇怪,因为完全相同的东西在其他机器上也能完美运行。

最佳答案

这发生在我身上,仅在一种资源(一种方法)上,我不明白为什么。同一个包中的类中的所有方法,具有相同的注释,对 ResponseEntity.ok(...) 的相同调用等都可以正常工作。

但不是这个。

原来我忘了在我的 POJO 类上生成 getters !

一旦我添加了它们,它就起作用了。

希望它最终可以节省一些时间......

关于rest - Spring Boot 应用程序 : No converter found for return value of type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33832735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com