(类型=内部服务器错误,状态=500)。未找到类型返回值的转换器:com.test.SearchVO 类
Posted
技术标签:
【中文标题】(类型=内部服务器错误,状态=500)。未找到类型返回值的转换器:com.test.SearchVO 类【英文标题】:(type=Internal Server Error, status=500). No converter found for return value of type: class com.test.SearchVO 【发布时间】:2016-08-14 15:44:40 【问题描述】:我有下面的源代码,我试图在 Spring Boot 中运行它,但绑定没有发生,它抱怨它找不到转换器。
出现意外错误:
(type=Internal Server Error, status=500). No converter found for return value of type: class com.test.SearchVO
。
据我所知,弹簧靴不需要杰克逊罐在路径中。但是我尝试添加它仍然无法正常工作。我在不同的论坛尝试过类似的问题,找不到任何好的答案,请帮助。
了解springboot会照顾自动转换吗?
我尝试发布我无法接收值等的值。
我从事过 spring 应用程序并第一次尝试 spring boot,因为没有 spring 调度程序。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class SpringAnnotationTest
@RequestMapping(value = "/searchUser", method = RequestMethod.POST)
public SearchVO searchUser(@RequestBody SearchVO user)
System.out.println(user.toString());
return user;
@RequestMapping(value = "/getSearchUser", method = RequestMethod.GET)
public SearchVO getSearchUser()
SearchVO user = new SearchVO();
System.out.println(user.toString());
return user;
public static void main(String[] args) throws Exception
SpringApplication.run(SpringAnnotationTest.class, args);
我的 pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>test</name>
<description>test</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- <scope>test</scope> -->
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是 VO 课程。
public class SearchVO implements Serializable
/**
*
*/
private static final long serialVersionUID = 1L;
private String empid;
private String nickname;
private String email;
private String phone;
@Override
public String toString()
// TODO Auto-generated method stub
return "<EMPID>"+this.empid+"<NICKNAME>"+nickname+"<email>"+email+"<phone>"+phone;
堆栈跟踪
java.lang.IllegalArgumentException: No converter found for return value of type:
class com.test.SearchVO
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessage
ConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMeth
odProcessor.java:178) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessage
ConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMeth
odProcessor.java:153) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponse
BodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:16
5) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandle
rComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80) ~
[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocabl
eHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126) ~[spring-
webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
andlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817) ~[sprin
g-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
andlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731) ~[spring-web
mvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapt
er.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.5.RELEASE.ja
r:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(Dispatch
erServlet.java:959) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(Dispatche
rServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(Frame
workServlet.java:968) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServl
et.java:859) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat
-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkSer
vlet.java:844) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat
-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:292) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
) ~[tomcat-embed-websocket-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConf
iguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConf
iguration.java:237) ~[spring-boot-actuator-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilter
Internal(WebRequestTraceFilter.java:112) ~[spring-boot-actuator-1.3.3.RELEASE.ja
r:1.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(
RequestContextFilter.java:99) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:240) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:207) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInter
nal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEA
SE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
输入 Json “empid”:“哈利”, “昵称”:“哈利”, “电子邮件”:“harry@gmail.com”, “电话”:“12323232”
【问题讨论】:
你能发布 SearchVO 并完成堆栈跟踪吗? 我已经添加了堆栈跟踪和 vo 类。 我认为您需要为 SearchVO 类设置 getter 和 setter。在内部调用 getter 和 setter 来映射值。试试看它是否有效。SearchVO
有无参数构造函数吗?
为字段添加setter和getter
【参考方案1】:
请确保您拥有 SearchVO 类字段的公共 getter 方法。
【讨论】:
这没有提供问题的答案。一旦你有足够的reputation,你就可以comment on any post;相反,provide answers that don't require clarification from the asker.【参考方案2】:将@EnableAutoConfiguration
替换为@SpringBootApplication
注释。
@SpringBootApplication 包括:
-
@Configuration - 通知 Spring 这是一个 Config 类。
@EnableAutoConfiguration - 启用基于类路径中的类触发 Spring Boots 自动配置的 AutoConfiguration。
@ComponentScan - 通知 Spring 扫描
@Components
(即@RestController, @Controller, @Repository, @Service
)
这里是 Small Demo 与您的请求映射。
考虑将 @RestController
移动到 abc.xyz.controller 包下的单独类中,其中 abc.xyz 是包含 SpringBootApplication 类的包,这将确保 @ComponentScan
查找所有原型。
【讨论】:
以上是关于(类型=内部服务器错误,状态=500)。未找到类型返回值的转换器:com.test.SearchVO 类的主要内容,如果未能解决你的问题,请参考以下文章
Whitelabel 错误页面出现意外错误(类型=内部服务器错误,状态=500)。空标识符
HTTP 状态 404 – 未找到!!!!或有时 Http 500 [重复]
Spring Boot Web 应用程序给出 500 内部服务器错误,而不是 404 未找到