2017-03-01 8 views
0

Ich bin neu im Gebrauch ehcache und ich verwende Einstellungen unten. Als ich einrichten ehcache 3 mein Projekt kompilieren gut, aber wenn ich Abfrage Endpunkt zu senden, ich habe Fehler:Fehler, wenn ich ehcache verwende

2017-03-01 11:46:02,032 ERROR org.springframework.transaction.interceptor.TransactionInterceptor : Application exception overridden by rollback error 
java.lang.AbstractMethodError: org.hibernate.cache.ehcache.internal.regions.EhcacheTimestampsRegion.put(Lorg/hibernate/engine/spi/SessionImplementor;Ljava/lang/Object;Ljava/lang/Object;)V 
    at org.hibernate.cache.spi.UpdateTimestampsCache.preInvalidate(UpdateTimestampsCache.java:95) 
    at org.hibernate.engine.spi.ActionQueue.invalidateSpaces(ActionQueue.java:618) 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:584) 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434) 
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337) 
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) 
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295) 

application.gradle

buildscript { 
    ext { 
     springBootVersion = '1.3.5.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse-wtp' 
apply plugin: 'spring-boot' 
apply plugin: 'war' 


war { 
    baseName = 'deliverypoint' 
    version = '0.0.1-SNAPSHOT' 
} 
sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

configurations { 
    providedRuntime 
} 

ext { 
    jodaTimeVersion = '2.9.4' 
} 

dependencies { 
    compile('org.springframework.boot:spring-boot-starter') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-jersey') 
    compile('org.springframework.boot:spring-boot-starter-web') 
    compile('org.apache.tomcat.embed:tomcat-embed-jasper') 
    compile('org.postgresql:postgresql') 
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    compile("joda-time:joda-time:$jodaTimeVersion") 
    compile("org.apache.tomcat:tomcat-dbcp:7.0.55") 
    compile group: 'org.jadira.usertype', name: 'usertype.jodatime', version: '2.0.1' 
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.1.0.Final' 
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.1.0.Final' 
    compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.2.4.Final' 
    compile(group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.5') 

    compile('org.springframework.security:spring-security-taglibs') 

    providedRuntime('javax.servlet:jstl') 


    compile("org.springframework.boot:spring-boot-starter-security") 
    compile("org.springframework.security.oauth:spring-security-oauth2") 
    compile group: 'org.springframework.social', name: 'spring-social-core', version: '1.1.4.RELEASE' 
    compile group: 'org.springframework.social', name: 'spring-social-security', version: '1.1.4.RELEASE' 

    compile group: 'org.modelmapper.extensions', name: 'modelmapper-spring', version: '0.7.7' 

    // https://mvnrepository.com/artifact/com.google.maps/google-maps-services 
    compile group: 'com.google.maps', name: 'google-maps-services', version: '0.1.16' 

// compile (group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.1.Final') { 
//  exclude group: 'net.sf.ehcache', module: 'ehcache' //by both name and group 
// } 
// 
// compile group: 'org.ehcache', name: 'ehcache', version: '3.3.0' 


    compile group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.6.11' 
    compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.1.Final' 
    compile group: 'org.springframework', name: 'spring-context-support', version: '4.1.4.RELEASE' 
    // compile('org.springframework.boot:spring-boot-starter-cache') 
} 

bootRun { 
    systemProperties System.properties 
} 

Config Hibernate:

import org.hibernate.SessionFactory; 
import org.hibernate.cfg.AvailableSettings; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.core.env.Environment; 
import org.springframework.orm.hibernate5.HibernateTemplate; 
import org.springframework.orm.hibernate5.HibernateTransactionManager; 
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; 

import javax.sql.DataSource; 
import java.util.Map; 
import java.util.Properties; 
@Configuration 
    public class DatabaseConfig { 

     @Autowired 
     private Environment env; 

     @Autowired 
     private ApplicationContext applicationContext; 

     @Bean 
     public Map<String, DataSource> dataSourceMap() { 
      return applicationContext.getBeansOfType(DataSource.class); 
     } 

     /** 
     * init startup resources like sql scripts 
     * 
     * @return DataSourceInitializer 
     */ 

     @Bean 
     public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) { 
      HibernateTransactionManager hibernateTransactionManager = new HibernateTransactionManager(sessionFactory); 
      hibernateTransactionManager.setAutodetectDataSource(false); 
      return hibernateTransactionManager; 
     } 

     @Bean 
     public HibernateTemplate hibernateTemplateMain(SessionFactory sessionFactory) { 
      return new HibernateTemplate(sessionFactory); 
     } 

     public Properties hibernateProperties() { 
      return new Properties() { 
       { 
        setProperty("hibernate.hbm2ddl.auto", env.getProperty("datasources.ddl-auto")); 
        setProperty("hibernate.dialect", env.getProperty("datasources.hibernate.dialect")); 
        setProperty("hibernate.show_sql", env.getProperty("datasources.show-sql")); 
        setProperty("hibernate.format_sql", env.getProperty("datasources.format-sql")); 
        setProperty("hibernate.multiTenancy", env.getProperty("datasources.multiTenancyStrategy")); 
        setProperty("hibernate.multi_tenant_connection_provider", env.getProperty("datasources.multiTenancyConnectionProvider")); 
        setProperty("hibernate.tenant_identifier_resolver", env.getProperty("datasources.multiTenancyIdentifierResolver")); 
        setProperty("hibernate.default_schema", env.getProperty("datasources.default_schema")); 
        setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true"); 

        setProperty(AvailableSettings.USE_SECOND_LEVEL_CACHE, "true"); 
        setProperty(AvailableSettings.USE_QUERY_CACHE, "true"); 
        setProperty(AvailableSettings.CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"); 
        setProperty("net.sf.ehcache.configurationResourceName","/ehcache.xml"); 
       } 
      }; 
     } 

     @Bean 
     public LocalSessionFactoryBean sessionFactoryMain(Map<String, DataSource> dataSourceMap) { 
      DataSource dataSource = dataSourceMap.get("datasourcemain"); 
      LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); 
      sessionFactory.setDataSource(dataSource); 
      sessionFactory.setPackagesToScan("io.default.deliverypoints"); 
      sessionFactory.setHibernateProperties(hibernateProperties()); 
      return sessionFactory; 
     }   
    } 

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?> 
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" 
     monitoring="autodetect" dynamicConfig="true" shared="true"> 

    <diskStore path="java.io.tmpdir/ehcache" /> 

    <defaultCache maxEntriesLocalHeap="5000" eternal="true" 
        timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30" 
        maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120" 
        memoryStoreEvictionPolicy="LRU" statistics="true"> 
     <persistence strategy="localTempSwap" /> 
    </defaultCache> 

    <cache name="billCache" maxEntriesLocalHeap="10000" 
      eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 

    <cache name="org.hibernate.cache.internal.StandardQueryCache" 
      maxEntriesLocalHeap="5000" eternal="false" timeToLiveSeconds="120"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 

    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache" 
      maxEntriesLocalHeap="5000" eternal="true"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 
</ehcache> 

In der Haupt-Spring-Boot-App verwende ich @EnableCaching. Und Anmerkung, die ich auf Entität verwenden:

@SuppressWarnings("serial") 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="billCache") 
@Cacheable 

Antwort

0

Sie sind eine abstrakte Methode Ausnahme bekommen, weil Sie den Anbieter zwischen Hibernate und ehcache verkabeln müssen.

Die Methode dafür ist in der documentation here.

Kurz gesagt, die Config Abschnitt für die Hibernate-Eigenschaften muss auch beinhalten:

  setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider"); 
+0

Vielen Dank für Antwort, aber das ist mein Problem nicht behoben ( –

+0

Problem beheben, aber jetzt ein anderes Problem: org. glassfish.jersey.server.ContainerException: java.lang.AbstractMethodError: org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy.get (Lorg/Ruhezustand/engine/spi/SessionImplementor; Ljava/lang/Object; J) Ljava/lang/Object; –

+0

Erneut - weil Sie etwas vermissen, das verkabelt werden sollte, oder Sie haben Anmerkungen, die als Metadaten für all das verwendet werden, nicht korrekt angewendet Um diese Frage zu betrachten, benötigt man wahrscheinlich auch mindestens eine Ihrer Entitätsklassen als Referenz. – lscoughlin

Verwandte Themen