zoukankan      html  css  js  c++  java
  • Invalid property 'mediaTypes' of bean class [org.springframework.web.servlet.view.ContentNegotiating

    今天看见公司使用的spring版本比较低,想着升级一波,一开始是使用的3.1,后来为了解决跨域问题,将spring版本升级为了4.3,因为跨域的Core类是4.2加入的
    在这里插入图片描述
    然后启动发现报错:

    在这里插入图片描述
    打开springmvc配置文件,发现配置视图解析的类报错了,就是后续spring版本中的mediaTypes居然不支持setter方法了
    在这里插入图片描述

     <!-- 配置ViewResolver 。可用多个ViewResolver 。使用order属性排序。   InternalResourceViewResolver 放在最后-->
        <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
            <property name="order" value="1"></property>
            <property name="mediaTypes">
                <map>
                    <!-- 告诉视图解析器,返回的类型为json格式 -->
                    <entry key="json" value="application/json" />
                    <entry key="xml" value="application/xml" />
                    <entry key="htm" value="text/htm" />
                    <entry key="html" value="text/html" />
                </map>
            </property>
            <property name="defaultViews">
                <list>
                    <!-- ModelAndView里的数据变成JSON -->
                    <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
                </list>
            </property>
            <property name="ignoreAcceptHeader" value="true"></property>
        </bean>
    

    然后将那一段改为:

       <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
        <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
            <property name="messageConverters">
                <list>
                    <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                        <property name="supportedMediaTypes">
                            <list>
                                <value>text/html;charset=UTF-8</value>
                                <value>application/json;charset=UTF-8</value>
                            </list>
                        </property>
                    </bean>
                </list>
            </property>
        </bean>
    

    皆可以了,注意,复制有时候会有特殊字符,我考这一篇就有:
    转:
    https://blog.csdn.net/csdn_terence/article/details/53888741

    世界上所有的不公平都是由于当事人能力不足造成的.
  • 相关阅读:
    java中取两位小数 但不要四舍五入
    从字符串中提取数字 java正则表达式
    SQL实现 列转行(MySQL中)
    sql如何根据时间取出最新的数据记录
    动画 很精辟的
    week 与 strong区别 精辟的解释
    The executable was signed with invalid entitlements新设备run出现这个问题
    在iOS中创建静态库
    网址
    nginx单机1w并发设置
  • 原文地址:https://www.cnblogs.com/javayida/p/13346971.html
Copyright © 2011-2022 走看看