2017-10-10 90 views
2

我正在用Spring Framework 4.0.6編寫一個Web應用程序,我必須安排一個小例程,每天在同一時間運行。我通過使用@Scheduled註釋並在我的dispatcher-servlet.xml中添加標籤來嘗試它,但是當應用程序啓動時我得到一個SAXParseException。我的XML文件是這樣的:cvc-complex-type.2.4.c:匹配的通配符是嚴格的,但是對元素的任務沒有聲明:註釋驅動

<?xml version="1.0" encoding="UTF-8"?> 
<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:util="http://www.springframework.org/schema/util" 
    xmlns:sws="http://www.springframework.org/schema/web-services" 
    xmlns:int="http://www.springframework.org/schema/integration" 
    xmlns:int-ws="http://www.springframework.org/schema/integration/ws" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:task="http://www.springframework.org/task/spring-task" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/web-services 
    http://www.springframework.org/schema/web-services/web-services.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util.xsd 
    http://www.springframework.org/schema/integration 
    http://www.springframework.org/schema/integration/spring-integration.xsd 
    http://www.springframework.org/schema/integration/ws 
    http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd 
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee.xsd 
    http://www.springframework.org/schema/data/jpa 
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd 
    http://www.springframework.org/schema/task 
    http://www.springframework.org/schema/task/spring-task.xsd"> 

<context:component-scan base-package="com.somepackage" /> 
    <sws:annotation-driven /> 
    <tx:annotation-driven transaction-manager="transactionManager"/> 
    <task:annotation-driven /> 

我得到的錯誤是下面:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 37 in XML document from ServletContext resource [/WEB-INF/spring-ws-servlet.xml] is invalid; nested exception is org. 
    xml.sax.SAXParseException; lineNumber: 37; columnNumber: 31; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'task:annotation-driven'. 
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399) 
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) 
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) 
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181) 
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217) 
      Truncated. see log file for complete stacktrace 
    Caused By: org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 31; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'task:annotation-driven 
    '. 
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198) 
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) 
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396) 
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) 
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284) 
      Truncated. see log file for complete stacktrace 

預先感謝您的回答。

回答

0

看這裏是一個錯誤:

xmlns:task="http://www.springframework.org/task/spring-task" 

所以,您嘗試使用一個名稱空間作爲spring-task同時它的位置是:

http://www.springframework.org/schema/task 

命名空間必須是完全一致的聲明位置。

相關問題