Search
Calendar
June 2025
S M T W T F S
« May    
1234567
891011121314
15161718192021
22232425262728
2930  
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:

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

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

<property name="cache" value="customCache"/>

Leave a Reply