Spring + MyBatis + Ehcache 整合 CacheManager 版本>2.5,命名空间冲突 解决

<!--ehcache 加载xml配置信息-->
    <bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <!--虽然有默认值,但我发现源码的逻辑是在判定null后设置默认值: __DEFAULT__的,
        而在判定null后,如果有过个CacheManager,并不是通过静态方法 CacheManager.create()来获取单例的,而是new CacheManager,有相同的命名空间,就会产生冲突
        从Spring框架整合Ehcache就会用该cacheManagerName属性作为命名空间,覆盖ehcache.xml中的name命名空间
        从MyBatis加整合Ehcache,配置文件ehcache.xml只能在类路径下,以ehcache.xml中的name作为命名空间,同时MyBatis的ehcache.xml中需要一个defaultCache的配置
        所以如此配置,可以在Spring + MyBatis + Ehcache 整合时,实例化两个net.sf.ehcache.CacheManager,各用各的,也避免命名空间的冲突-->
        <property name="cacheManagerName" value="ehcacheManager"/>
        <property name="configLocation" value="classpath:ehcache.xml"/>
        <property name="acceptExisting" value="true"/>
    </bean>

ehcache.xml 中的 name 命名空间

<ehcache name="ec">

猜你喜欢

转载自blog.csdn.net/u011730792/article/details/79353952