2011-05-13 57 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>