- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚开始使用 ehcache,我使用下面的设置。当我设置 ehcache 3 时,我的项目编译良好,但是当我在端点上发送查询时,出现错误:
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)
应用程序.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
}
配置 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>
在主要的 spring boot 应用程序中,我使用 @EnableCaching。和我在实体上使用的注释:
@SuppressWarnings("serial")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="billCache")
@Cacheable
最佳答案
您收到一个抽象方法异常,因为您需要在 hibernate 和 ehcache 之间连接提供程序。
执行此操作的方法在 documentation here 中.
简而言之,您的 hibernate 属性配置部分还需要包括:
setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider");
关于java - 使用 ehcache 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42528910/
对于 Lucene,我们有一个很好的工具箱,如 Luke查看、诊断、编辑等。我们是否有类似的工具(至少显示)用于 EhCache(当我们启用 diskPersistent 时)? 最佳答案 我不知道有
我必须集成 spring 和 ehcache,并尝试使用 来实现它阻塞缓存 图案 有一个选项自填充缓存范围 对于 共享(默认)和方法 .你能解释一下有什么区别吗? 还有注解 @可缓存与 自我填充 旗
我有一个配置为使用 JPA 和 Hibernate 的大型 Java 应用程序。据说它还被配置为对实体和查询缓存使用 ehcaching。但是,我打开了 sql 日志记录,并且没有缓存任何实体。所有实
正如您在标题中看到的那样,问题很清楚,很高兴听到您对 adv./disadv 的想法。它们之间的差异。 更新:我决定使用 Hazelcast,因为它具有分布式缓存/锁定机制等优点,并且在适应您的应用程
我知道属性“updateCheck”可以在 XML 中设置为“false”,如下所示: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xs
我在不同的类中创建了两个方法,并使用 @Cacheable 注释对它们进行注释,并给出了相同的缓存名称,如下所示: class MyClass{ @Cacheable(value="inSco
我正在尝试新的 ehcache 版本,但我注意到,显然,没有搜索 API。 这是正常的还是我错过了什么?文档没有说明这一点。 最佳答案 主要原因是在缓存中搜索在到期和驱逐时具有非常奇怪的语义。由于 E
在 Ehcache 2 中,可以使用 calculateInMemorySize() 获取内存中的大小,例如: CacheManager manager = CacheManager.create()
如果我有以下配置: timeToIdleSeconds 的值是多少用于缓存 test ?它会从默认缓存继承,因此等于 120,还是会采用手册中给出的默认值,即 0(无穷大)? 最佳答案 timeT
我正在使用 ehcache 通过 hibernate 缓存实体。 查看ehcache监视器,一切似乎都工作正常(刷新将缓存计数设置为零,然后重新加载将计数放回一),但是如果我直接在数据库上更改某些值并
ehcache 是一个高度可配置的野兽,示例相当复杂,通常涉及多层接口(interface)。 有没有人遇到过最简单的例子,它只是在内存中缓存一个数字(不是分布式的,没有 XML,尽可能少的 java
net.sf.ehcache.CacheManager.ALL_CACHE_MANAGERS 是否有替代品?在 org.ehcache ehcach
使用 Ehcache 3.1,我可以知道当前存储在 ehcache 中的元素的大小以及缓存到目前为止的命中和未命中数。我认为 2.6 有 .getStatistics(),它做类似的事情,但是我在 3
我是 Spring 框架中的 ehcache v/s ehcache-core 的初学者,我的 pom.xml 使用的是 ehcache 版本 1.5.0 net.sf.ehcache ehcach
我正在运行一个使用 Ehcache 3.4.0 的网络应用程序。我有一个缓存配置,它定义了 1000 个内存中对象的简单默认值: java.lang.Object java.lang
我想找到一种在 ehCache 装饰器类中使用 Spring 依赖注入(inject)的好方法。我的 ehcache.xml 具有以下缓存配置: 我有以下装饰器实现: public cl
我想弄清楚最新版本的 Ehcache(2.7.0、2.7.1、2.7.2、2.7.4、2.7.5、2.8.0)是否真的有新版本的 ehcache-core或者如果 ehcache-core 自版本 2
我们在 WebLogic Server 10.3.4 上运行 Spring 3.0.5 Web 应用程序Solaris with Sun JVM 1.6.0_x 64bit 使用 EhCache 2.
ehcache 3.8.1 是否不再自动获取源根目录下的 ehcache.xml 文件中的配置设置? 最佳答案 是的,看起来是这样,现在需要使用 XML 文件来完成 configuringe a Ca
http://ehcache.org/generated/2.9.0/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-use_supported_t
我是一名优秀的程序员,十分优秀!