spring cache ehcache 所需jar包

      对于spring cache的配置和使用网上说了很多了,不再重复了,现在描述一下所使用的jar包

      一 使用spring本身的cache

         

       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>

       二 使用ehcache

         

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.8.1</version>
        </dependency>

      

     特别说明:在使用ehcahe实现缓存的时候,不加入ehcache-2.8.1.jar的时候,在spring加入配置文件:

    

    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
          p:configLocation="ehcache.xml"/>

    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
          p:cacheManager-ref="ehcache"/>

   时, 在为cacheManager指定cacheManager引用时, IDE一直提示ehcache应该为net.sf.ehcache.CacheManager类型的,看了一下源码,

在类org.springframework.cache.ehcache.EhCacheCacheManager类中的cacheManager类型确实为net.sf.ehcache.CacheManager,

public class EhCacheCacheManager extends org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager {
    private net.sf.ehcache.CacheManager cacheManager;

 而引用ehcache为org.springframework.cache.ehcache.EhCacheManagerFactoryBean类型的,

进入类org.springframework.cache.ehcache.EhCacheManagerFactoryBean的源码可以看到:

public class EhCacheManagerFactoryBean implements org.springframework.beans.factory.FactoryBean<net.sf.ehcache.CacheManager>, 
org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean {

 类org.springframework.cache.ehcache.EhCacheManagerFactoryBean实现接口org.springframework.beans.factory.FactoryBean<net.sf.ehcache.CacheManager>

并且传入了net.sf.ehcache.CacheManager参数类型

 

而且类org.springframework.cache.ehcache.EhCacheManagerFactoryBean 有方法:

public net.sf.ehcache.CacheManager getObject() { /* compiled code */ }

 所以引入jar包ehcache-2.8.1.jar之后,spring的配置文件就不会再报错了!

 

说的非常乱,不过记住把上面三个jar包都给引入就行了!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值