spring mvc <mvc:annotation-driven>配置使用出現問題

來源:互聯網
上載者:User

標籤:

我在使用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

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

spring mvc <mvc:annotation-driven>配置使用出現問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.