[英]Autowired spring bean null for cacheManager using ehcache spring annotations
[英]Wrong CacheManager is looked up Spring ehcache
我正在嘗試為我的項目配置帶有春天注釋的ehcache,並且出現此異常:
無法將[org.springframework.cache.ehcache.EhCacheCacheManager]類型的值轉換為屬性'cacheManager'所需的[net.sf.ehcache.CacheManager]類型
我的上下文應用文件是這樣的:
<?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更改為另一個異常。
謝謝你能給我的幫助。
最好的祝福。
您正在手動創建一個Spring CacheManager,並且它被annotation-driven
機制隱式使用(由於它是“ cacheManager” ID)。 注釋機制實際上將為您完成此操作,但是它需要底層的緩存實現。 因此,將您的代碼更改為以下內容:
<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" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.