Spring Boot Application:没有findtypes返回值的转换器

我正在编写一个简单的REST API,按照这个 Spring-Boot教程。 在我的本地开发机器上(Ubuntu 15.04和Windows 8.1),一切都像一个魅力。

我有一台旧的32位Ubuntu 12.04 LTS服务器,我想部署我的REST服务。

开始日志是好的,但只要我发送GET请求到/ user / {id}端点,我得到以下错误:

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 

整个stacktrace在这里发布。

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

受影响的控制器是:

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

任何帮助将不胜感激。 这是非常奇怪的,因为完全相同的东西完全适用于其他机器。

提前致谢!

您应该对您的pom.xml和mvc-dispatcher-servlet.xml文件进行一些更改:将以下依赖项添加到您的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:

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

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

但不是这个。

事实证明,我已经忘记了在我的POJO课上生成getters!

一旦我加入他们的工作。

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

当你忘记“build”调用时会发生这种情况:

 return ResponseEntity.status(HttpStatus.BAD_REQUEST); 

应该:

 return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();