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

    世界上所有的不公平都是由于当事人能力不足造成的.
  • 相关阅读:
    webdav srs相关
    How To Configure WebDAV Access with Apache on Ubuntu 14.04
    ubuntu 编译lighttpd
    srs编译及推流测试
    Compile pciutils (lspci, setpci) in Windows x86,在 Windows x86 平台下编译 pciutils (lspci, setpci)
    mingw MSYS2 区别
    Qt之美(三):隐式共享
    Qt之美(二):元对象
    Qt之美(一):d指针/p指针详解
    C++的栈空间和堆空间
  • 原文地址:https://www.cnblogs.com/javayida/p/13346971.html
Copyright © 2011-2022 走看看