簡體   English   中英

grails 3(spring-boot)-如何配置休眠二級緩存

[英]grails 3 (spring-boot) - how to configure hibernate second level cache

嘗試將ehcache用作休眠二級緩存時,出現以下異常:org.hibernate.cache.NoCacheRegionFactoryAvailableException:應用程序中使用了二級緩存,但未提供屬性hibernate.cache.region.factory_class

我試圖在application.yml中配置它:

spring:
  jpa:
    properties:
      hibernate:
        cache:
          region:
            factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory

和:

grails:
    hibernate:
      cache:
        use_second_level_cache: true
        provider_class: net.sf.ehcache.hibernate.EhCacheProvider
        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>

然后在application.yml中:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM