我目前正在尝试创建我的第一个带弹簧的休息服务,我不想让他回来XML结果(基于JAXB).
在一个非常基本的休息控制器上:
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
public class CVIController {
@RequestMapping(value = "/resume")
public @ResponseBody
Integer getResume() {
return 5;
}
}
spring-servlet.xml 非常空:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="fr.urouen"
/>
<mvc:annotation-driven />
</beans>
还有 JDK8 下的 Tomcat 服务器,因此我可以确定所有模块都默认加载在 JVM 上...我抛出了以下异常:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.lang.Integer
我不想使用 Jackson,因为我知道 JAXB 可以处理这个问题。
但是在修改了我的代码的某些部分之后,我仍然找不到她被抛出的原因的答案。
Edit 1:
我尝试创建一个带有吸气剂的虚拟类,正如答案所说
public class Dummy {
private int value;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
@RestController
public class CVIController {
@RequestMapping(value = "/resume")
public ResponseEntity<Dummy> getResume() {
Dummy dummy = new Dummy();
dummy.setValue(5);
return new ResponseEntity<Dummy>(dummy, HttpStatus.OK);
}
}
但仍然得到完全相同的结果:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class fr.urouen.model.Dummy