0
votes

Reading the javadoc for EhCacheManagerFactoryBean and EhCacheFactoryBean I figured that:

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml"/>

<bean id="locationCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"
      p:cacheManager-ref="cacheManager"
      p:cacheName="locationCache"/>

would create a cache that I then can @Autowired in. But I must be missing something because this is what I get:

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'locationCache' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: net.sf.ehcache.Cache.(Ljava/lang/String;ILnet/sf/ehcache/store/MemoryStoreEvictionPolicy; ZLjava/lang/String;ZJJZJLnet/sf/ehcache/event/RegisteredEventListeners; Lnet/sf/ehcache/bootstrap/BootstrapCacheLoader;II)V

I've tried ehcache 1.7.2, 1.6.2 and 1.5.0.

It works if I specify <cache name="locationCache" /> in ehcache.xml but I prefer to have my configuration done in applicationsContext.xml

<cache name="locationCache" /> 
1
which version of spring?skaffman
you need the 3.1 to use hecache!German Attanasio

1 Answers

3
votes

The missing constructor belongs to Ehcache 1.3, and it still exists in the newer versions. May be, you have some problem with dependecnies. If you use maven, try mvn dependency:tree -Dverbose=true and look for conflicts.