Spring版本4.2.0,Hibernate 4.1.4
这是我的Controller功能:
@RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET)
@ResponseBody
public List<Company> listforCompanies() {
List<Company> listOfCompanies= new ArrayList<Company>();
listOfCompanies = companyManager.getAllCompanies();
return listOfCompanies;
}
Run Code Online (Sandbox Code Playgroud)
杰克逊JSON映射器依赖Pom.xml:
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
获取列表ArrayList,但返回时会显示以下错误:
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/IrApp] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList] with root cause
java.lang.IllegalArgumentException: No converter found for return …Run Code Online (Sandbox Code Playgroud) 我根据编写一个简单的REST API 这个弹簧引导教程.在我的本地开发机器(Ubuntu 15.04和Windows 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
Run Code Online (Sandbox Code Playgroud)
然后在堆栈跟踪中:
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.LinkedHashMap
Run Code Online (Sandbox Code Playgroud)
整个堆栈跟踪都发布在这里.
我查看了一些引用此错误的答案,但这些似乎并不适用于我的问题,因为我使用的是Spring-Boot,没有任何xml配置.
受影响的控制器是:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.这是非常奇怪的,因为完全相同的东西在其他机器上工作.
提前致谢!
我正在使用Spring启动来托管REST API.我希望始终发送JSON响应,而不是标准的错误响应,即使浏览器正在访问URL以及自定义数据结构.
我可以使用@ControllerAdvice和@ExceptionHandler来实现自定义异常.但我无法找到任何好的方法来处理标准和处理错误,如404和401.
有没有什么好的模式如何做到这一点?
java ×2
json ×2
rest ×2
spring ×2
spring-boot ×2
converters ×1
spring-4 ×1
spring-mvc ×1
ubuntu ×1