【发布时间】:2020-12-28 14:16:36
【问题描述】:
我试图在不使用 hibernate.cfg.xml 文件的情况下配置 hibernate,而是使用注释。在我激活二级缓存以访问命中、获取和未命中计数等统计信息之前,它工作正常。 当我将选项 use_second_level_cache 设置为 true 时,我收到以下错误:
引起:org.springframework.beans.factory.BeanCreationException: 创建类中定义的名称为“getSessionFactory”的 bean 时出错 路径资源 [myPath/hibernate/config/HibernateConfiguration.class]: 调用 init 方法失败;嵌套异常是 java.lang.AbstractMethodError: 方法 org/hibernate/cache/ehcache/EhCacheRegionFactory.start(Lorg/hibernate/boot/spi/SessionFactoryOptions;Ljava/util/Map;)V 是抽象的
以下是相关配置行:
properties.put(USE_SECOND_LEVEL_CACHE, true);
properties.put(CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.EhCacheRegionFactory");
和(部分)我的 pom:
<hibernate.version>5.2.10.Final</hibernate.version>
...
<!-- Hibernate Core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Hibernate Ehcache -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
我最初想到的是版本问题或 jar 冲突,但似乎无法发现问题。任何帮助将不胜感激。
【问题讨论】:
-
你使用什么hibernate和ehcache版本?
-
5.2.10.Final - 我更新了最初的帖子
-
你使用什么ehcache 版本?
-
同hibernate,5.2.10-Final(见pom.xml)
标签: java spring hibernate ehcache