我有一个使用两个数据源的Spring boot + Spring数据JPA应用程序。我已经使用LocalContainerEntityManagerFactoryBean配置了实体管理器,如下所示:
#include <stdio.h>
int main(void)
{
printf("Hello World\n");
printf("Press the Enter key to continue\n");
(void) getc(stdin);
return 0;
}
这对我来说很好。 为两个数据源添加缓存 然后我想为此添加memcached。我将属性添加到setJpaPropertyMap。 但是我仍然得到错误hibernate.cache.region.factory_class没有给出
我设置了以下属性:
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean userEntityManager() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(userDataSource());
em.setPackagesToScan(new String[] { "uk.co.o2.smip.validator.dao.entity.user" });
em.setSharedCacheMode(SharedCacheMode.ALL);
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("hibernate.hbm2ddl.auto", "validate");
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
em.setJpaPropertyMap(properties);
我已经检查过类路径中提到的类文件。不知道什么是错的。
例外
properties.put("spring.jpa.properties.hibernate.cache.use_second_level_cache", "true");
properties.put("spring.jpa.properties.hibernate.cache.use_query_cache", "true");
properties.put("spring.jpa.properties.hibernate.cache.region.factory_class", "kr.pe.kwonnam.hibernate4memcached.Hibernate4MemcachedRegionFactory");
properties.put("spring.jpa.properties.hibernate.cache.default_cache_concurrency_strategy", "NONSTRICT_READ_WRITE");
properties.put("spring.jpa.properties.hibernate.cache.region_prefix", "validatorCache");
properties.put("spring.jpa.properties.hibernate.cache.use_structured_entries", "false");
properties.put("spring.jpa.properties.h4m.adapter.class", "kr.pe.kwonnam.hibernate4memcached.spymemcached.SpyMemcachedAdapter");
properties.put("spring.jpa.properties.h4m.timestamper.class", "kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamperMemcachedImpl");
properties.put("spring.jpa.properties.h4m.adapter.spymemcached.hosts", "localhost:11211");
properties.put("spring.jpa.properties.h4m.adapter.spymemcached.hashalgorithm", "KETAMA_HASH");
properties.put("spring.jpa.properties.h4m.adapter.spymemcached.operation.timeout.millis", "5000");
properties.put("spring.jpa.properties.h4m.adapter.spymemcached.transcoder", "kr.pe.kwonnam.hibernate4memcached.spymemcached.KryoTranscoder");
properties.put("spring.jpa.properties.h4m.adapter.spymemcached.cachekey.prefix", "validator");
properties.put("spring.jpa.properties.h4m.adapter.spymemcached.kryotranscoder.compression.threashold.bytes", "20000");
properties.put("spring.jpa.properties.h4m.expiry.seconds", "600");
properties.put("spring.jpa.properties.h4m.expiry.seconds.validatorCache.org.hibernate.cache.spi.UpdateTimestampsCache", "86400");
properties.put("spring.jpa.properties.h4m.expiry.seconds.validatorCache.org.hibernate.cache.internal.StandardQueryCache", "3600");
// properties.put("spring.jpa.properties.h4m.expiry.seconds.validatorCache.certificates", "1800");
properties.put("spring.jpa.properties.h4m.expiry.seconds.validatorCache.users", "1800");