一尘不染

ehcache休眠4

hibernate

在我的应用程序中,我使用了hibernate-core-4.1.8 jar,并希望将ehCache用作第二级缓存。我当前使用的jar是ehcache-
core-2.5.0。我将其放置在WebContetn / WEB-INF / lib文件夹中,并将其放置在类路径中。

我的hibernate.cfg.xml看起来像这样:

<hibernate-configuration>
    <session-factory>   
    ....    
        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="hibernate.cache.use_query_cache">true</property>
    </session-factory>
</hibernate-configuration>

放置在JavaResources / src文件夹中的ehcache.xml:

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

    <defaultCache
                maxElementsInMemory="100000"
                eternal="false"
                timeToIdleSeconds="1000"
                timeToLiveSeconds="1000"
                overflowToDisk="false"
                />
</ehcache>

运行我的应用程序时,找不到org.hibernate.cache.ehcache.EhCacheRegionFactory类:

java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.ehcache.EhCacheRegionFactory
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
    at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:444)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:275)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
    at creator.controllers.MyFactory.<clinit>(MyFactory.java:18)
    at creator.controllers.SchoolDAO.getList(SchoolDAO.java:98)
    .....

阅读 312

收藏
2020-06-20

共1个答案

一尘不染

您需要hibernate- ehcache.jar通过下载来包含它,或者您正在使用maven像这样将其放入您的依赖项中

<dependency>
<artifactId>hibernate-ehcache</artifactId>
<groupId>org.hibernate</groupId>
<version>4.0.0.CR6</version>
</dependency>
2020-06-20