Spring MVC 中的 Redisson Hibernate 2L 缓存配置问题

Problem with Redisson Hibernate 2L cache config in Spring MVC

我正在尝试在 Spring MVC 项目中配置 Redisson Hibernate 2L 缓存。 我遵循了教程,尽管其中大部分都致力于 Spring Boot。 我在 pom.xml 文件中添加了依赖项:

<dependency>
  <groupId>org.redisson</groupId>
  <artifactId>redisson</artifactId>
  <version>3.12.0</version>
</dependency>
<dependency>
  <groupId>org.redisson</groupId>
  <artifactId>redisson-hibernate-53</artifactId>
  <version>3.11.6</version>
</dependency>

在persistance.xml中(二级缓存暂时设置为false,因为我只是试图让它启动应用程序):

<property name="hibernate.cache.region.factory_class" value="org.redisson.hibernate.RedissonRegionFactory"/>
  <property name="hibernate.cache.use_second_level_cache" value="false"/>
  <property name="hibernate.cache.use_query_cache" value="false"/>

在我的配置文件中:

    @Bean(destroyMethod="shutdown")
  RedissonClient redisson() {
    Config config = new Config();
    config.useClusterServers()
            .addNodeAddress("redis://127.0.0.1:6379");
    return Redisson.create(config);
  }

  @Bean
  CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
    Map<String, CacheConfig> config = new HashMap<>();
    config.put("testMap",
            new CacheConfig(120000, 180000)); //2min TTL and 3min max idle time
    return new RedissonSpringCacheManager(redissonClient, config);
  }

项目正在正确构建,但是当我尝试 运行 它时,我收到一个错误:

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.CacheImplementor]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.getService(SessionFactoryServiceRegistryImpl.java:97)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:238)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:938)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:141)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
    ... 63 more
Caused by: java.lang.IllegalStateException: Cache provider not started
    at org.hibernate.cache.spi.AbstractRegionFactory.verifyStarted(AbstractRegionFactory.java:65)
    at org.hibernate.cache.spi.support.RegionFactoryTemplate.buildTimestampsRegion(RegionFactoryTemplate.java:66)
    at org.hibernate.cache.internal.EnabledCaching.<init>(EnabledCaching.java:80)
    at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:33)
    at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:24)
    at org.hibernate.service.spi.SessionFactoryServiceInitiator.initiateService(SessionFactoryServiceInitiator.java:30)
    at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:61)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
    ... 72 more
Caused by: org.hibernate.cache.CacheException: Unable to locate Redisson configuration
    at org.redisson.hibernate.RedissonRegionFactory.createRedissonClient(RedissonRegionFactory.java:107)
    at org.redisson.hibernate.RedissonRegionFactory.prepareForUse(RedissonRegionFactory.java:83)
    at org.hibernate.cache.spi.AbstractRegionFactory.start(AbstractRegionFactory.java:91)
    at org.hibernate.cache.internal.EnabledCaching.<init>(EnabledCaching.java:77)

我不知道我缺少什么来定位 Redisson 配置..? 如果有任何帮助,我将不胜感激!

期待redisson配置文件 https://github.com/redisson/redisson/wiki/2.-Configuration

您忘记定义 Redisson 配置的路径:

<property name="hibernate.cache.redisson.config" value="/redisson.yaml" />