2014-08-27 48 views
0

我試圖用彈簧anotations爲我的項目配置了Ehcache和我得到這個異常:CacheManager的錯誤中查找春天的Ehcache

無法將類型的值org.springframework.cache.ehcache.EhCacheCacheManager ]所需類型[net.sf.ehcache.CacheManager]財產 '的CacheManager'

我的背景下aplication文件是這樣的:

<?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:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" 
xmlns:p="http://www.springframework.org/schema/p" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd  
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-  spring-1.1.xsd"> 
<ehcache: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:configLocation="/WEB-INF/ehcache.xml"/> 
</beans> 

我我我做錯了什麼?如果我爲net.sf.ehcache.CacheManager更改rg.springframework.cache.ehcache.EhCacheCacheManager,則會得到另一個異常。

感謝您的任何幫助,你可以給我。

最好的問候。

回答

1

您正在手動創建一個Spring CacheManager,並且它正在被隱式使用(由於它的「cacheManager」id)由annotation-driven機制。註解機制實際上會爲你做,但它需要底層的緩存實現。所以,你的代碼更改爲以下:

<ehcache:annotation-driven/> 
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
    p:configLocation="/WEB-INF/ehcache.xml"/> 

注意:你可以擺脫

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

致謝,我已經能夠部署我的項目,@ user2264997但現在我得到的印象是它根本沒有做任何緩存:(你知道如何檢查嗎?(我知道不是最初的問題的一部分,但我真的會幫助我) – 2014-08-27 21:32:16

+0

假設你有一個「管理」界面/服務器在你的應用程序,只需將「cacheManager」注入到管理服務,獲取想要檢查並轉儲它的內容的['Cache'](http://ehcache.org/apidocs/net/sf/ehcache/Cache.html)。 – ikumen 2014-08-28 04:26:28