Srping整合EhCache

引入的Jar包如下:

 

<!-- 配置hibernate session工厂 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <!-- 设置Hibernate方言 -->
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <!-- 是否打印sql -->
                <prop key="hibernate.show_sql">false</prop>
                <!-- 格式化sql -->
                <prop key="hibernate.format_sql">false</prop>
                <!-- 是否自动更新表 -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                
          <!-- hibernate4配置 hibernate.cache.region.factory_class -->
          <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
          <!-- hibernate3配置 hibernate.cache.provider_class -->
                <!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> -->
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.jdbc.batch_size">100</prop>
            </props>
        </property>
        ....
    </bean>

这里要特别注意一下的就是:如果是hibernate4,配置

          <!-- hibernate4配置 hibernate.cache.region.factory_class -->
          <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>

             如果是hibernate3,配置

          <!-- hibernate3配置 hibernate.cache.provider_class -->
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>

 我开始时同时设置了这两个总是报这种类找不到的错误

下面是ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
    <!--  -->
    <diskStore path="E:/SSHBoot/cache" />
    <defaultCache maxElementsInMemory="10000" eternal="false"
        overflowToDisk="true" timeToIdleSeconds="120" timeToLiveSeconds="180"
        diskPersistent="false" diskExpiryThreadIntervalSeconds="60" />

    <cache name="org.hibernate.cache.StandardQueryCache"
        maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300"
        timeToLiveSeconds="4200" overflowToDisk="true" />

    <cache name="org.hibernate.cache.UpdateTimestampsCache"
        maxElementsInMemory="5000" eternal="true" timeToIdleSeconds="0"
        timeToLiveSeconds="0" overflowToDisk="false" />
</ehcache>

 

你可能感兴趣的:(Srping整合EhCache)