Grails3(SpringBoot)-如何配置hibernate二级缓存

Grails3(SpringBoot)-如何配置hibernate二级缓存,hibernate,grails,spring-boot,grails-3.0,Hibernate,Grails,Spring Boot,Grails 3.0,当尝试将ehcache用作hibernate二级缓存时,出现以下异常: org.hibernate.cache.NoCacheRegionFactoryAvailableException:应用程序中使用了二级缓存,但未提供hibernate.cache.region.factory_类属性 我试图在application.yml中配置它: spring: jpa: properties: hibernate: cache: regio

当尝试将ehcache用作hibernate二级缓存时,出现以下异常: org.hibernate.cache.NoCacheRegionFactoryAvailableException:应用程序中使用了二级缓存,但未提供hibernate.cache.region.factory_类属性

我试图在application.yml中配置它:

spring:
  jpa:
    properties:
      hibernate:
        cache:
          region:
            factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
spring:
    jpa:
        properties:
            hibernate.cache.use_second_level_cache: true
            hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
以及:


但是这些似乎都没有帮助。

如果删除
grails
顶级配置,后者应该可以工作,因为grails查找的是“hibernate.blah”而不是“grails.hibernate.blah”:

  hibernate:
      cache:
        use_second_level_cache: true
        provider_class: net.sf.ehcache.hibernate.EhCacheProvider
      region:
         factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory

您应该在
hibernate
之前删除
grails
。Grails希望区域的结构在缓存下

记住标签在yml文件中很重要

所以代码应该是这样的:

hibernate:
cache:
    queries: false
    use_second_level_cache: true
    use_query_cache: false
    region:
        factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'

这是一个迟来的回答,但可能在将来对某人有所帮助

尝试在pom.xml中添加此依赖项:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
    <version>5.2.2.Final</version>
</dependency>

我有点困惑。我生成了一个版本为3.0.1的新应用程序,我在application.yml中看到:-grails>hibernate>cache>querys:false
spring:
    jpa:
        properties:
            hibernate.cache.use_second_level_cache: true
            hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory