2017-10-07 87 views
0

我目前正在嘗試爲我的應用程序實現緩存,並且我面臨一個錯誤「cvc-complex-type.2.4.c:匹配通配符是嚴格的,但是對於元素'cache:annotation-driven'沒有聲明。」在我的pom.xml中。我在這裏錯過了什麼嗎?cvc-complex-type.2.4.c:匹配的通配符是嚴格的,但是對於元素'cache:annotation-driven'沒有聲明。

的pom.xml

<?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:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache" 
xmlns:p="http://www.springframework.org/schema/p" 
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.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache.xsd 
        http://www.springframework.org/schema/tx/spring-tx.xsd"> 

<context:annotation-config /> 
<context:component-scan base-package="packages path" /> 

<!-- Enables the caching through annotations --> 
<cache:annotation-driven /> 

<!-- Generic cache manager based on the JDK ConcurrentMap --> 
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> 
    <property name="caches"> 
     <set> 
      <bean 
       class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" 
       p:name="task" /> 
     </set> 
    </property> 
</bean> 

回答

0

你在屬性中的schemaLocation順序是錯誤的。取而代之的

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.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/cache 
       http://www.springframework.org/schema/cache/spring-cache.xsd 
       http://www.springframework.org/schema/tx/spring-tx.xsd" 

應該

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.xsd 
       http://www.springframework.org/schema/cache 
       http://www.springframework.org/schema/cache/spring-cache.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx.xsd" 

中的schemaLocation值總是由元素對的。第一個元素表示在xmlns屬性中使用的模式的標識符,每對中的第二個元素表示xsd文件的位置。在您的代碼中,您基本上告訴解析器,標識符http://www.springframework.org/schema/tx的xsd文件位於http://www.springframework.org/schema/cache,標識符http://www.springframework.org/schema/cache/spring-cache.xsd的xsd文件位於http://www.springframework.org/schema/tx/spring-tx.xsd

+0

啊我看看現在是如何工作的。謝謝您的幫助 :) – Sebastian

相關問題