2011-05-13 59 views
3

我試圖按照spring doc使用3.1 spring緩存配置和命名空間。我還下載了最新的罐子從春季的網站,但仍然我得到 關於命名空間Spring 3.1緩存命名空間問題

這個問題
Unable to locate Spring NamespaceHandler for element 'cache:annotation-driven' of schema namespace 'http://www.springframework.org/ 

模式/高速緩存」

Spring配置文件

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


cache:annotation-driven /> 

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/> 
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
    p:config-location="classpath:ehcache.xml"/> 
+0

我承擔粘貼時錯過的<<是錯誤的。 – Bozho 2011-05-13 08:07:27

回答

6

您需要spring-context-support.jarspring-context.jar類路徑。

spring-contextCacheNamespaceHandler類。

(注意,春天是現在使用不同的命名方案,爲他們的罐子,但contextcontext support的名稱被保留)

+0

@Bozho我已經添加spring-context.jar,但我cudn,t在下載的源代碼中找到spring-cache.jar – Vish 2011-05-13 09:14:00

+0

@Vish對不起,我的不好,看到更新。 – Bozho 2011-05-13 09:51:09

+0

@Bozho org.springframework.context.support-3.1.0.M1.jar已經在我的項目中了。我應該添加pring-context-support-2.5.6.jar – Vish 2011-05-13 10:15:17

3

對於Maven用戶,添加以下的依賴:

<spring-version>3.1.0.RELEASE</spring-version> 
    <ehcache-version>2.4.2</ehcache-version> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context-support</artifactId> 
     <version>${spring-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>net.sf.ehcache</groupId> 
     <artifactId>ehcache-core</artifactId> 
     <version>${ehcache-version}</version> 
    </dependency>