SSM框架报错:元素 ‘annotation-driven‘ 必须不含字符 [子级], 因为该类型的内容类型为“仅元素”。

在SSM框架整合fastjson的时候出了一个莫名其妙的BUG,报错内容为:元素 ‘mvc:annotation-driven’ 必须不含字符 [子级], 因为该类型的内容类型为“仅元素”。

我的mvc:annotation-driven内容为:

<mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json</value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <value>WriteMapNullValue</value>
                        <value>QuoteFieldNames</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

搜索了一圈后,有一个博客突然让我想到了一个问题。解决办法很简单。

在mvc:annotation-driven标签所在文件头部检查引入,应该有

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
   	http://www.springframework.org/schema/context/spring-context-3.0.xsd
   	http://www.springframework.org/schema/mvc 
   	http://www.springframework.org/schema/mvc/spring-mvc.xsd

尤其要注意的是最后一行http://www.springframework.org/schema/mvc/spring-mvc.xsd有没有写错,修改前我的最后一行为http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

修改完成后不报错,正常运行

参考

https://blog.csdn.net/a_keep_going_roc/article/details/89818900

https://blog.csdn.net/Hhellooneworld/article/details/100830519

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值