我无法使用hibernate配置ehcache

Kas*_*yap 0 hibernate ehcache

我使用的相应jar文件如下:

  • 的Ehcache-3.2.0
  • hibernate-ehcache-5.0.2.Final
  • hibernate-core-5.0.2.Final

配置是这样的:

  <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 
 <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
 <prop key="hibernate.cache.use_second_level_cache" >true</prop>
 <prop key="hibernate.cache.use_query_cache">true</prop>
 <prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>
Run Code Online (Sandbox Code Playgroud)

我收到这样的错误:

java.lang.NoClassDefFoundError:net/sf/ehcache/CacheException

帮我解决这个问题.

Hen*_*nri 6

您正在使用Ehcache 3(这是好的),但正在使用与Ehcache 2兼容的区域工厂.

对于符合JCache的Ehcache 3,您应该使用org.hibernate.cache.jcache.JCacheRegionFactory.

你会在这里找到一个完整的例子:https://github.com/ehcache/ehcache3-samples/tree/master/fullstack.看看README.md有趣的文件.

注意:正如路易斯在评论中提到的,你需要Hibernate 5.2才能获得JCache支持.