博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mediaTypes错误(Bean property 'mediaTypes' is not writable or has an invalid setter method.)
阅读量:2489 次
发布时间:2019-05-11

本文共 2024 字,大约阅读时间需要 6 分钟。

ERRORBean property 'mediaTypes' is not writable or has an invalid setter method. Does theparameter type of the setter match the return type of the getter?后续spring版本中的mediaTypes居然不支持setter方法了

(解决方法亲测有用)

错误描述

         一般的为了使用Json,对其配置:     

     
         
         
           
               
               
               
           
               
           
               
               
                           
   

         结果是会出现上述错误提示:Bean property'mediaTypes' is not writable or has an invalid setter method. Does theparameter type of the setter match the return type of the getter?

      意思是ContentNegotiatingViewResolver中不再支持mediaTypes的setter方法了。究其原因,是因为ContentNegotiatingViewResolver的setMediaTypes(Map<String,String>mediaTypes)方法已经被弃用(deprecated),不仅如此,一同被deprecated的的还有setFavorPathEctension 、setFavorParameter、setIgnoreAcceptHeader等方法,但是,这些方法都转移到了ContentNegotiationManager中了,为此,要想对其使用,可以转换为对ContentNegotiationManager的配置。

       另外,对于数据形式的多种形式表述(html/xml/json/pdf/excel),Spring有两种表述形式:

              ・ org.springframework.web.servlet.view.ContentNegotiatingViewResolver

              ・ org.springframework.http.converter.HttpMessageConverte

       ContentNegotiatingViewResolver虽然是ViewResolver一族的,但是并不解析视图,而是将其委托给其他的ViewResolver。

       介于spring的两种表述方法,但是ContentNegotiatingViewResolver弃用了setMediaTypes,所以用contentNegotiationManager替换,但是配置contentNegotiationManager是通过ContentNegotiationManagerFactoryBean来实现的,所以,选择第一种办法,要对ContentNegotiationManagerFactoryBean进行配置。

       所以,在这里,呈现不同格式的数据可以有两种办法:ContentNegotiationManagerHttpMessageConverter 

解决方法

           首先在pom.xml文件中加入依赖,然后对其选择一种配置方案即可成功,亲测有用。

加入依赖

   

方法1:配置ContentNegotiationManager

com.fasterxml.jackson.core
jackson-databind
2.5.4

方法2:配置HttpMessageConverter 

 
text/html;charset=UTF-8
application/json;charset=UTF-8

友情链接:

转载地址:http://odlrb.baihongyu.com/

你可能感兴趣的文章
记一次断电恢复ORA-01033错误
查看>>
C#修改JPG图片EXIF信息中的GPS信息
查看>>
从零开始的Docker ELK+Filebeat 6.4.0日志管理
查看>>
Sequelize的原始查询的时区问题
查看>>
How it works(1) winston3源码阅读(A)
查看>>
How it works(2) autocannon源码阅读(A)
查看>>
How it works(3) Tilestrata源码阅读(A)
查看>>
How it works(12) Tileserver-GL源码阅读(A) 服务的初始化
查看>>
uni-app 全局变量的几种实现方式
查看>>
echarts 为例讲解 uni-app 如何引用 npm 第三方库
查看>>
uni-app跨页面、跨组件通讯
查看>>
springmvc-helloworld(idea)
查看>>
JDK下载(百度网盘)
查看>>
idea用得溜,代码才能码得快
查看>>
一篇掌握python魔法方法详解
查看>>
数据结构和算法5-非线性-树
查看>>
数据结构和算法6-非线性-图
查看>>
数据结构和算法7-搜索
查看>>
数据结构和算法8-排序
查看>>
windows缺少dll解决办法
查看>>