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" />