springmvc spring mybatis 添加ehcache

版本:spring 3.2  ehcache 2.6.5 spring

  1. 引入jar  mybatis-ehcache.jar  ehcache.jar  以及其余的依赖包缓存

  2. 编辑ehcache.xml    reference :   http://www.ehcache.org/ehcache.xmlmybatis

    3.在mybatis配置文件中 引入ehcache.xml  
app

    ehcache 版本为2.6 及以上 不允许多个同名的ehcacheManager , 貌似添加shared =true  就能够解决
spa

   <!-- 配置Ehcache缓存管理器,读取配置文件 -->
    <bean id="ehCacheManagerFactoryBean" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:resource/ehcache.xml"></property>
        <property name="shared" value="true"></property>
    </bean>
    
    <!-- 配置缓存管理器,获取cache -->
     <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" >
        <property name="cacheManager" ref="ehCacheManagerFactoryBean" />
    </bean>

 4.在mapper.xml 中配置<cache/>配置项
code

相关文章
相关标签/搜索