I am not able to configure ehcache with hibernate

十年热恋 提交于 2020-01-07 04:11:09

问题


corresponding jar files i used are below :

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

configuration is like this :

  <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>

I am getting error like this :

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

help me to getout of this issue.


回答1:


I think you need this artifact:

<dependency> 
   <groupId>net.sf.ehcache</groupId> 
   <artifactId>ehcache-core</artifactId> 
   <version>2.10.3</version> 
</dependency>

It contains the net.sf.ehcache packages / classes that your application is looking for.

Based on your hibernate property:

<prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>



回答2:


You are using Ehcache 3 (which is good) but are using a region factory that is Ehcache 2 compatible.

For Ehcache 3, which is JCache compliant, you should use org.hibernate.cache.jcache.JCacheRegionFactory.

You will find a full example here: https://github.com/ehcache/ehcache3-samples/tree/master/fullstack. Have a look at the README.md to find the interesting files.

Note: As Louis mentioned in the comment, you need Hibernate 5.2 to get JCache support.



来源:https://stackoverflow.com/questions/41973637/i-am-not-able-to-configure-ehcache-with-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!