就是使用Spring提供的springmodules和EHCache來簡化程序的開發,經過配置文件來完成提供緩存。參考springmodules的文檔。spring
一、配置ehcache.xml文件緩存
二、建立Spring EHCache的配置xml文件框架
配置文件代碼示例(調試經過):ide
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ehcache="http://www.springmodules.org/schema/ehcache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"> <bean id="EhCacheFacade" class="org.springmodules.cache.provider.ehcache.EhCacheFacade"> <property name="failQuietlyEnabled" value="true" /> <property name="cacheManager"> <bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:ehcache.xml"> </property> </bean> </property> </bean> <bean id="cachingInterceptor" class="org.springmodules.cache.interceptor.caching.MethodMapCachingInterceptor"> <property name="cacheProviderFacade" ref="EhCacheFacade" /> <property name="cachingModels"> <props> <prop key="com....test.Manager.get*"> cacheName=dictCache </prop> </props> </property> </bean> <bean id="flushingInterceptor" class="org.springmodules.cache.interceptor.flush.MethodMapFlushingInterceptor"> <property name="cacheProviderFacade" ref="EhCacheFacade" /> <property name="flushingModels"> <props> <prop key="com....test.Manager.update*"> cacheNames=dictCache </prop> </props> </property> </bean> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <value>*anager</value> </property> <property name="interceptorNames"> <list> <value>flushingInterceptor</value> <value>cachingInterceptor</value> </list> </property> </bean> <bean id="manager" class="com...test.Manager"></bean> </beans>