2017-09-16 2 views
0

Rest Spring起動アプリケーションの実行中に以下の例外が発生しました。Rest Spring起動アプリケーションで第2レベルのキャッシュを実装中にエラーが発生しました

Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath 

configディレクトリにapplication.propertiesファイルとehcache.xmlファイルがあります。

application.properties

#Second level caching 
hibernate.cache.use_second_level_cache=true 
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 

logging.level.org.hibernate.SQL=DEBUG 
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE 

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?> 
<ehcache> 
    <defaultCache eternal="true" maxElementsInMemory="1000" overflowToDisk="false"/> 
    <cache name="simpleCache" maxElementsInMemory="100" eternal="true" overflowToDisk="false" /> 
</ehcache> 

エンティティークラス: -

import org.hibernate.annotations.CacheConcurrencyStrategy; 
import javax.persistence.Column; 
import java.util.Date; 
import javax.persistence.Cacheable; 
import javax.persistence.Table; 
import javax.persistence.Id; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Index; 
import javax.persistence.Entity; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import org.hibernate.annotations.Cache; 
import org.hibernate.annotations.CacheConcurrencyStrategy; 

@Entity 
@Cacheable 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "simpleCache") 

私はエンティティに「@Cacheライン」を削除し、「@Cacheable(真)」「@Cacheable」に変更した場合、私はエラーを取得していない午前

dependencies { 
    compile('org.springframework.boot:spring-boot-starter-actuator') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-web') 
    runtime('org.springframework.boot:spring-boot-devtools') 
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache 
    compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '4.0.1.Final' 
    // https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core 
    compile group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.5.0' 
    runtime('org.postgresql:postgresql') 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
} 

build.gradle。しかし、この場合は、DBから変更されていないエンティティデータを得るたびに取得します。クエリが実行されています。

ご協力いただきますようお願い申し上げます。

答えて

0

キャッシュが休止状態で使用されていないようです。

私はehcacheを古いバージョンによって少し驚いて、あなたが使用していることを休止:

compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '4.0.1.Final' 
compile group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.5.0' 

Latest Spring boot definesこれらのバージョン:

とにかく
<ehcache3.version>3.2.2</ehcache3.version> 
<hibernate.version>5.0.12.Final</hibernate.version> 

、私はあなたがやることをお勧めするものこれらのスプリングブートバージョンを使用して、ehcache3に接着するためのjsr-107(jcache)サポートを実行します(update your ehcache.xml to the latest versionが必要です)

this simple spring boot app using ehcache3をご覧になることをお勧めします。また、スプリングブートとehcache/jsr-107にもっと慣れていると感じたら、a full fledged jhipster/spring boot/hibernate/ehcache app source codeにジャンプしてください。

0

アンソニーはまったく正しいです。それは、あなたは直接の問題は、プロパティはspring.jpa.properties.hibernate.cache.region.factory_classspring.jpa.properties.hibernate.cache.use_query_cache=trueでなければならないということです。

関連する問題