启动为二级缓存配置的Wildfly时出现以下异常。我在persistence.xml
中启用了二级缓存。如果我在property
下方删除,则会正常启动。以下配置有什么问题?
的persistence.xml
<property name="hibernate.cache.infinispan.statistics" value= "true"/>
standalone.xml (默认为wildfly)
<cache-container name="hibernate" default-cache="local-query" module="org.hibernate.infinispan">
<local-cache name="entity">
<transaction mode="NON_XA"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="local-query">
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="timestamps"/>
</cache-container>
例外:
在属性“可用”时启用统计信息&#39;设置为false。
日志
... 7 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:264)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:228)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:242)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 9 more
Caused by: org.hibernate.cache.CacheException: Unable to start region factory
at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:418)
at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:49)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:28)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:20)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:46)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:254)
... 14 more
Caused by: org.infinispan.commons.CacheConfigurationException: ISPN000372: **Statistics are enabled while attribute 'available' is set to false.**
at org.infinispan.configuration.cache.JMXStatisticsConfigurationBuilder.validate(JMXStatisticsConfigurationBuilder.java:69)
at org.infinispan.configuration.cache.ConfigurationBuilder.validate(ConfigurationBuilder.java:203)
at org.infinispan.configuration.cache.ConfigurationBuilder.build(ConfigurationBuilder.java:246)
at org.infinispan.configuration.cache.ConfigurationBuilder.build(ConfigurationBuilder.java:236)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.defineGenericDataTypeCacheConfigurations(InfinispanRegionFactory.java:636)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:394)
... 19 more
答案 0 :(得分:4)
正如错误消息所述,统计信息已启用(通过hibernate.cache.infinispan.statistics=true
中的persistence.xml
),但缓存容器统计信息不可用,因为默认情况下未启用。
Wildfly 10(和JBoss EAP 7)在应用程序启动时验证hibernate统计信息(请参阅JMXStatisticsConfigurationBuilder:64)。由于启用了应用程序统计信息,但容器统计信息不可用,因此会引发异常。
要激活缓存容器统计信息,您需要在statistics-enabled="true"
和cache-container
配置中添加 local-cache
:
<cache-container name="hibernate" default-cache="local-query"
module="org.hibernate.infinispan"
statistics-enabled="true">
<local-cache name="entity"
statistics-enabled="true">
<transaction mode="NON_XA"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="local-query"
statistics-enabled="true">
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<local-cache name="timestamps"
statistics-enabled="true"/>
</cache-container>