我正在使用Spring Boot和Spring数据JPA获得多数据源的应用程序。
我收到了以下异常hibernate.cache.region.factory_class
未设置,但我在代码中设置它。 Spring Boot在我设置之前检查它,或者无法读取我的设置。
caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:83)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:364)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 130 more
8-Nov-2015 00:23:46.220 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive D:\sw\apache-tomcat-8.0.23\webapps\SecurityValidator.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SecurityValidator]]
我有以下代码。仅粘贴相关部分: -
Spring Boot配置类,用于显示排除的自动配置: -
@EnableAsync
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,})
@ComponentScan("com.demo")
public class Initializer extends SpringBootServletInitializer {
我的两个数据源配置: -
@Bean
public LocalContainerEntityManagerFactoryBean certEntityManager() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(certificateDataSource());
em.setPackagesToScan(new String[] { "dao.entity.cert" });
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
HashMap<String, Object> properties1 = new HashMap<String, Object>();
properties1.put("hibernate.hbm2ddl.auto", "validate");
properties1.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
em.setJpaPropertyMap(properties1);
Properties properties = new Properties();
properties.setProperty("spring.jpa.properties.hibernate.cache.use_second_level_cache", "true");
properties.setProperty("spring.jpa.properties.hibernate.cache.use_query_cache", "true");
properties.setProperty("spring.jpa.properties.hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.EhCacheRegionFactory");
properties.setProperty("spring.jpa.properties.hibernate.cache.default_cache_concurrency_strategy", "NONSTRICT_READ_WRITE");
properties.setProperty("spring.jpa.properties.hibernate.cache.region_prefix", "valCache");
properties.setProperty("spring.jpa.properties.hibernate.cache.use_structured_entries", "false");
properties.setProperty("spring.jpa.properties.h4m.adapter.class", "kr.pe.kwonnam.hibernate4memcached.spymemcached.SpyMemcachedAdapter");
properties.setProperty("spring.jpa.properties.h4m.timestamper.class", "kr.pe.kwonnam.hibernate4memcached.timestamper.HibernateCacheTimestamperMemcachedImpl");
properties.setProperty("spring.jpa.properties.h4m.adapter.spymemcached.hosts", "localhost:11211");
properties.setProperty("spring.jpa.properties.h4m.adapter.spymemcached.hashalgorithm", "KETAMA_HASH");
properties.setProperty("spring.jpa.properties.h4m.adapter.spymemcached.operation.timeout.millis", "5000");
properties.setProperty("spring.jpa.properties.h4m.adapter.spymemcached.transcoder", "kr.pe.kwonnam.hibernate4memcached.spymemcached.KryoTranscoder");
properties.setProperty("spring.jpa.properties.h4m.adapter.spymemcached.cachekey.prefix", "vali");
properties.setProperty("spring.jpa.properties.h4m.adapter.spymemcached.kryotranscoder.compression.threashold.bytes", "20000");
properties.setProperty("spring.jpa.properties.h4m.expiry.seconds", "600");
properties.setProperty("spring.jpa.properties.h4m.expiry.seconds.valCache.org.hibernate.cache.spi.UpdateTimestampsCache", "86400");
properties.setProperty("spring.jpa.properties.h4m.expiry.seconds.valCache.org.hibernate.cache.internal.StandardQueryCache", "3600");
properties.setProperty("spring.jpa.properties.h4m.expiry.seconds.valCache.cert", "1800");
properties.setProperty("spring.jpa.properties.h4m.expiry.seconds.valCache.users", "1800");
em.setJpaProperties(properties);
return em;
}
同样对于第二个数据源: -
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean userEntityManager() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
..................
-----------------
}
我使用以下依赖项: -
</dependency>
<dependency>
<groupId>kr.pe.kwonnam.hibernate4memcached</groupId>
<artifactId>hibernate4-memcached-core</artifactId>
<version>0.7</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>kr.pe.kwonnam.hibernate4memcached</groupId>
<artifactId>hibernate4-memcached-spymemcached-adapter</artifactId>
<version>0.7</version>
</dependency>
欢迎任何建议或指示。
更新错误
我仍然无法完全向前移动,但我现在收到以下错误。
Caused by: net.spy.memcached.OperationTimeoutException: Mutate operation timed out,unable to modify counter [validator.validatorCache.users@]
at net.spy.memcached.MemcachedClient.mutate(MemcachedClient.java:1663) ~[spymemcached-2.10.2.jar:2.10.2]
at net.spy.memcached.MemcachedClient.mutateWithDefault(MemcachedClient.java:1835) ~[spymemcached-2.10.2.jar:2.10.2]
at net.spy.memcached.MemcachedClient.incr(MemcachedClient.java:1767) ~[spymemcached-2.10.2.jar:2.10.2]
at kr.pe.kwonnam.hibernate4memcached.spymemcached.SpyMemcachedAdapter.getNamespacedKey(SpyMemcachedAdapter.java:141) ~[hibernate4-memcached-spymemcached-adapter-0.7.jar:na]
at kr.pe.kwonnam.hibernate4memcached.spymemcached.SpyMemcachedAdapter.set(SpyMemcachedAdapter.java:167) ~[hibernate4-memcached-spymemcached-adapter-0.7.jar:na]
at kr.pe.kwonnam.hibernate4memcached.regions.GeneralDataMemcachedRegion.put(GeneralDataMemcachedRegion.java:86) ~[hibernate4-memcached-core-0.7.jar:na]
at kr.pe.kwonnam.hibernate4memcached.strategies.MemcachedRegionAccessStrategy.putFromLoad(MemcachedRegionAccessStrategy.java:52) ~[hibernate4-memcached-core-0.7.jar:na]
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:221) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1115) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.processResultSet(Loader.java:973) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:921) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2554) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2540) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.Loader.list(Loader.java:2365) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:315) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:67) ~[spring-data-jpa-1.8.0.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_20]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_20]
我通过删除属性位更正了属性设置。这是一个错字。但现在我收到了上述错误。
答案 0 :(得分:0)
错误net.spy.memcached.OperationTimeoutException: Mutate operation timed out
似乎完全引用了memcached客户端/服务器交互。很可能memcached服务器在localhost:11211
上不可用。
答案 1 :(得分:-1)
您可以尝试以下工厂类:
net.sf.ehcache.hibernate.EhCacheRegionFactory
或
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
另外,要调试 - 我可能会继续检查实际的jar并查找该jar中工厂类的存在。