1、已经成功导入了相关jar包:hibernate-core 4.3.8Final;hibernate-ehcache 4.3.8Final和ehcache2.9.0
2、配置如下
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
${hibernate.hbm2ddl.auto}
${hibernate.dialect}
${hibernate.show_sql}
${hibernate.format_sql}
none
<!-- 开启查询的二级缓存 如果不需要就不设置 -->
true
<!-- 开启二级缓存 ehcache -->
true
<!-- Hibernate4.0以上设置factory -->
org.hibernate.cache.ehcache.EhCacheRegionFactory
<!-- 二级缓存 ehcache的配置文件位置 -->
classpath:configs/ehcache.xml
其中也注意了hibernate4和3的区别了
3、在实体类以标签注入@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)后,启动项目会报错
4、错误如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'riskalertDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
······
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
······
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
······
九月 12, 2017 2:58:18 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class com.prosas.basic.utils.ProjectInit
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'riskalertDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
······
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
······
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
······
5、网上查了很多资料,都说这个错误是org.hibernate.cache.ehcache.EhCacheRegionFactory这行有问题,但是说的解决方法中都是改成这样啊,就是解决不了问题很苦恼,求大神解答!
关于springMVC+hibernate4+eacache二级缓存配置问题,启动一直报错
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog