spring mvc <mvc:annotation-driven>配置使用出现故障

我在使用converter进行全局的日期类型转换。

1。写converer

public class CustomDateConverter implements Converter<String, Date> {

    public Date convert(String s) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}

然后改动spingmvc.xml配置文件:

<!-- 配置日期转换器 注解驱动 -->
    <mvc:annotation-driven conversion-service="conversionService"/>

<!-- 配置日期转换器 -->
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
        <property name="converters">
            <list>
                <bean class="xyz.zhulei.core.controller.converter.CustomDateConverter"/>
            </list>
        </property>
    </bean>


可是执行的时候出显了这个错误:

HTTP Status 500 - Servlet.init() for servlet back threw exception

root cause

org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 68; cvc-complex-type.2.4.c: 通配符的匹配非常全面, 但无法找到元素 'mvc:annotation-driven' 的声明。
	com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
	com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
	com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
	com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
	com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)

原因在于,我引用spingmvc.xml中的头文件时3.0版本号的xsd,以下这个注解时3.1才有的,所以我把xsd文件的版本号换成4.0的就好了。

mvc:annotation-driven

原文地址:https://www.cnblogs.com/mfrbuaa/p/5228125.html