<此博客只为自己学习记录,解决方案是综合了网上各种解决思路和方法,最后实践加以解决后,作为备忘录的用途。>
报错内容如下:
nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.XXX.XXX
直接不废话, 出现这个问题的原因可能包含以下两个:
①springMVC的配置文件
dispatcherServlet-servlet.xml
里面没有对json转换器的配置信息。
②json的三个jar包导入
<
dependency
>
<
groupId
>
com.
fasterxml.
jackson.
core
<
/groupId>
<
artifactId
>
jackson
-
databind
<
/artifactId>
<
version
>
2.7
.4
<
/version></
dependency
>
<
dependency
>
<
groupId
>
com.
fasterxml.
jackson.
core
<
/groupId>
<
artifactId
>
jackson
-
core
<
/artifactId>
<
version
>
2.7
.4
<
/version></
dependency
>
<
dependency
>
<
groupId
>
com.
fasterxml.
jackson.
core
<
/groupId>
<
artifactId
>
jackson
-
annotations
<
/artifactId>
<
version
>
2.7
.4
<
/version>
<
/dependency>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
①的解决方案,在dispatcherServlet-servlet.xml
<
bean
class
=
"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
>
<
property
name
=
"messageConverters"
>
<
list
>
<!--json转换器-->
<
ref
bean
=
"mappingJacksonHttpMessageConverter"
/
>
<
/list>
<
/property>
<
/bean>
<
bean
class
=
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"
>
<
property
name
=
"messageConverters"
>
<
list
>
<
ref
bean
=
"mappingJacksonHttpMessageConverter"
/
>
<
/list>
<
/property>
<
/bean>
<
bean
id
=
"mappingJacksonHttpMessageConverter"
class
=
"org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
>
<
property
name
=
"supportedMediaTypes"
>
<
list
>
<
bean
class
=
"org.springframework.http.MediaType"
>
<
constructor
-
arg
index
=
"0"
value
=
"text"
/
>
<
constructor
-
arg
index
=
"1"
value
=
"plain"
/
>
<
constructor
-
arg
index
=
"2"
value
=
"UTF-8"
/
>
<
/bean>
<
bean
class
=
"org.springframework.http.MediaType"
>
<
constructor
-
arg
index
=
"0"
value
=
"*"
/
>
<
constructor
-
arg
index
=
"1"
value
=
"*"
/
>
<
constructor
-
arg
index
=
"2"
value
=
"UTF-8"
/
>
<
/bean>
<
bean
class
=
"org.springframework.http.MediaType"
>
<
constructor
-
arg
index
=
"0"
value
=
"text"
/
>
<
constructor
-
arg
index
=
"1"
value
=
"*"
/
>
<
constructor
-
arg
index
=
"2"
value
=
"UTF-8"
/
>
<
/bean>
<
bean
class
=
"org.springframework.http.MediaType"
>
<
constructor
-
arg
index
=
"0"
value
=
"application"
/
>
<
constructor
-
arg
index
=
"1"
value
=
"json"
/
>
<
constructor
-
arg
index
=
"2"
value
=
"UTF-8"
/
>
<
/bean>
<
/list>
<
/property> </
bean
>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
②的解决方案: 安装上面提到的jar包,下载导入即可。 maven项目就直接复制粘贴在pom.xml文件里面即可。
原网站版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://blog.51cto.com/u_13519022/5562090