0
ehcache를 사용하면서 새로운 것이므로 아래 설정을 사용합니다. 내가으로 Ehcache 3을 설정할 때 내 프로젝트는 잘 컴파일,하지만 난 엔드 포인트에 쿼리를 보낼 때, 나는 오류가 있어요 :ehcache를 사용하고있을 때 오류가 발생했습니다.
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
}
구성의 최대 절전 모드 :
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>
주요 스프링 부팅 응용 프로그램에서 @EnableCaching을 사용합니다. 내가 엔티티에 사용 그리고 주석 :
@SuppressWarnings("serial")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="billCache")
@Cacheable
감사합니다, 그러나 이것은 내 문제 ( –
수정이 문제를 해결하지 않는,하지만 지금은 또 다른 문제가 있습니다 조직을. glassfish.jersey.server.ContainerException : java.lang.AbstractMethodError : org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy.get (Lorg/hibernate/engine/spi/SessionImplementor; Ljava/lang/Object; J) Ljava/lang/Object; –
다시 말하지만, 연결해야 할 내용이 누락되었거나이 모든 것에 메타 데이터로 사용되는 주석을 제대로 적용하지 않았기 때문입니다. 그 질문을보기 위해서는 엔티티 클래스 중 적어도 하나라도 참조 할 필요가있을 것입니다. – lscoughlin