将ehcache配置为二级缓存

时间:2015-08-10 11:39:14

标签: java spring hibernate ehcache

我在Spring 3.2.14.RELEASE和hibernate 4.2.2.Final上的应用程序中配置ehcache。我在服务器中部署应用程序时出错:

Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory []

这是我的配置文件:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
    <version>4.3.11.Final</version>
            <exclusions>
                <exclusion>
                    <groupId>net.sf.ehcache</groupId>
                    <artifactId>ehcache-core</artifactId>
                </exclusion>
            </exclusions>
</dependency>       

Persistencia.xml

<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
            <!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
            <property name="hibernate.hbm2ddl.auto" value="none"/>
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultNamingStrategy"/>
            <property name="hibernate.connection.charSet" value="UTF-8"/>
            <!-- Uncomment the following two properties for JBoss only -->
            <!-- property name="hibernate.validator.apply_to_ddl" value="false" /-->
            <!-- property name="hibernate.validator.autoregister_listeners" value="false" /-->
            <property key="hibernate.cache.use_second_level_cache">true</property>
            <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>           
            <property key="net.sf.ehcache.configurationResourceName">/ehcache.xml</property>
            <!-- <property key="hibernate.cache.use_query_cache">true</property> -->
        </properties>
    </persistence-unit>
</persistence>

ehcache.xml中

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    updateCheck="false" xsi:noNamespaceSchemaLocation="ehcache.xsd" name="notificationsCacheManager" updateCheck="true"
    monitoring="autodetect" dynamicConfig="true">

    <diskStore path="java.io.tmpdir" />

    <defaultCache maxEntriesLocalHeap="10000" eternal="false"
        timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30"
        maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU" statistics="true">
        <persistence strategy="localTempSwap" />
    </defaultCache>

    <cache name="com.test.notifications.domain.ClientOauth"  maxEntriesLocalHeap="10000"
                eternal="false"
                timeToIdleSeconds="300"
                timeToLiveSeconds="600"
                <persistence strategy="localTempSwap"/>

    <cache name="org.hibernate.cache.internal.StandardQueryCache"
                maxElementsInMemory="10000"
                eternal="false
                timeToLiveSeconds="86400"
                overflowToDisk="false"
                memoryStoreEvictionPolicy="LRU" />          

</ehcache>

我的配置有什么问题吗?

0 个答案:

没有答案