我正在尝试整合" hibernate-redis"作为Spring-boot应用程序中的Hibernate二级缓存提供程序。我按照github页面中的说明操作。
https://github.com/hibernate-redis/hibernate-redis
但是,应用程序失败并出现以下错误。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: Method org/hibernate/cache/redis/SingletonRedisRegionFactory.start(Lorg/hibernate/boot/spi/SessionFactoryOptions;Ljava/util/Properties;)V is abstract
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at com.example.ehcache.Application.main(Application.java:27) [classes/:na]
Caused by: java.lang.AbstractMethodError: Method org/hibernate/cache/redis/SingletonRedisRegionFactory.start(Lorg/hibernate/boot/spi/SessionFactoryOptions;Ljava/util/Properties;)V is abstract
at org.hibernate.cache.redis.SingletonRedisRegionFactory.start(SingletonRedisRegionFactory.java) ~[hibernate-redis-1.6.6.jar:na]
我的项目配置如下,
pom.xml "更新了对最低限度的依赖"
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--Cache-->
<dependency>
<groupId>com.github.hibernate-redis</groupId>
<artifactId>hibernate-redis</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
Application.properties
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
# Connection url for the database
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
# Username and password
spring.datasource.username=sa
spring.datasource.password=
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto=update
# Naming strategy
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true`enter code here`
spring.jpa.properties.hibernate.format_sql=true
# H2 Configuration
spring.datasource.driverClassName=org.h2.Driver
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Caching
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.redis.SingletonRedisRegionFactory
spring.jpa.properties.hibernate.cache.region_prefix=hibernate
spring.jpa.properties.hibernate.generate_statistics=true
spring.jpa.properties.hibernate.cache.use_structured_entries=true
spring.jpa.properties.hibernate.cache.provider_configuration_file_resource_path=hibernate-redis.properties
hibernate-redis.properties
##########################################################
#
# properties for hibernate-redis
#
##########################################################
# Redis Server for hibernate 2nd cache
redis.host=localhost
redis.port=6379
# use redis-sentinel cluster as opposed to a single redis server (use only if not using host/port)
# redis.sentinels = host1:26379,host2:26379,host3:26379
# redis.masterName = mymaster
# redis.timeout=2000
# redis.password=
# database for hibernate cache
# redis.database=0
redis.database=1
# Hibernate 2nd cache default expiry (seconds)
redis.expiryInSeconds=120
# expiry of hibernate.common region (seconds)
redis.expiryInSeconds.hibernate.common=0
# expiry of hibernate.book region (seconds)
redis.expiryInSeconds.hibernate.book=4
应用程序正常工作,没有缓存配置。有没有人有想法。谢谢!
该项目可在该地点找到。 https://github.com/janitham/SpringBoot-Hibernate-Ehcache/tree/SpringBoot-Hibernate-RedisCache