Recent Posts
Archives

PostHeaderIcon EhCache integration within Spring

Case

You have to use a EhCache in a couple of beans, instancied via Spring.

Fix

In your main Spring configuration file, declare the following block:

[xml]
<bean id="customCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="shared" value="false" />
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath*:ehcache.xml" />
</bean>
</property>
<property name="cacheName" value="SampleConfigOne" />
</bean>
[/xml]

Then, in any of your beans, declare the following property:

[xml]<property name="cache" value="customCache"/>[/xml]

Leave a Reply