Je reçois l'exception ci-dessous lors de l'exécution de l'application de démarrage Rest Spring. J'ai le fichier application.properties et ehcache.xml dans le répertoire config.Erreur lors de l'implémentation de la mise en cache de second niveau dans l'application de démarrage Rest Spring
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>
Classe Entité: -
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")
build.gradle
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')
}
Je ne reçois pas une erreur si je supprime la "@Cache ligne" dans l'entité et de changer "@Cacheable" à "@Cacheable (true)". Mais dans ce cas, chaque fois que je reçois les données d'entité un changement de la base de données. La requête est en cours de lancement.
Toute aide sera grandement appréciée!