Reputation: 13
i'm trying to configure ehcache with spring anotations for my project and i'm getting this Exception:
Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager] for property 'cacheManager'
My context aplication file is this:
<?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>
What i'm i doing wrong? if i change the rg.springframework.cache.ehcache.EhCacheCacheManager for net.sf.ehcache.CacheManager i get another exception.
Thanks for any help u can give me.
Best Regards.
Upvotes: 0
Views: 1878
Reputation: 11643
You are manually creating a Spring CacheManager and it's being implicitly used (due to it's "cacheManager" id) by annotation-driven
mechanism. The annotation mechanism will actually do that for you, but it's needs the underlying cache implementation. So change your code to the following:
<ehcache:annotation-driven/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:configLocation="/WEB-INF/ehcache.xml"/>
NOTE: you can get rid of
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" />
Upvotes: 1