0

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" /> 
2
  • which version of spring? Commented Jan 14, 2010 at 8:11
  • you need the 3.1 to use hecache! Commented Jun 8, 2012 at 21:38

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I found an old ehcache version (1.2.4) on the classpath. Removing that solved the problem. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.