gpt4 book ai didi

java - JBoss EAP 7 和 Ifinispan

转载 作者:行者123 更新时间:2023-12-02 11:52:14 33 4
gpt4 key购买 nike

我有一个用 JEE 编写的 Web 应用程序。我使用 hibernate 作为 JPA 提供程序,并且我想使用 Infinispan 作为二级缓存。当我浏览互联网时,我注意到只需要添加几行。我在 persistence.xml 中添加了这些行

<property name="hibernate.cache.provider_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
<property name="javax.persistence.sharedCache.mode" value="ENABLE_SELECTIVE"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
<property name="hibernate.cache.use_query_cache" value="true"/>

但是在 JBoss 上部署ear和war文件期间我收到一条错误消息

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:244)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
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)
... 83 more
Caused by: org.hibernate.cache.CacheException: Unable to start region factory
at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:415)
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:234)
... 88 more
Caused by: org.infinispan.jmx.JmxDomainConflictException: ISPN000034: There's already a JMX MBean instance type=CacheManager,name="SampleCacheManager" already registered under 'org.infinispan' JMX domain. If you want to allow multiple instances configured with same JMX domain enable 'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element
at org.infinispan.jmx.JmxUtil.buildJmxDomain(JmxUtil.java:52)
at org.infinispan.jmx.CacheManagerJmxRegistration.updateDomain(CacheManagerJmxRegistration.java:79)
at org.infinispan.jmx.CacheManagerJmxRegistration.buildRegistrar(CacheManagerJmxRegistration.java:73)
at org.infinispan.jmx.AbstractJmxRegistration.registerMBeans(AbstractJmxRegistration.java:37)
at org.infinispan.jmx.CacheManagerJmxRegistration.start(CacheManagerJmxRegistration.java:41)
at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:639)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:300)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:532)
at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:500)
at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:473)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:342)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:472)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:380)
... 93 more

更新
当我的持久单元看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>java:jboss/datasources/myDatasource</non-jta-data-source>
<mapping-file>META-INF/orm_mapping.xml</mapping-file>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
...
<properties>
...
<property name="hibernate.cache.use_second_level_cache" value="true" />
...
</properties>

</persistence-unit>

</persistence>

我遇到异常

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:66)
at org.hibernate.internal.SessionFactoryImpl.determineEntityRegionAccessStrategy(SessionFactoryImpl.java:619)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:332)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 83 more

将以下行添加到 persistence.xml 后

<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory" />

我仍然遇到 JMX MBean 异常

Caused by: org.infinispan.jmx.JmxDomainConflictException: ISPN000034: There's already a JMX MBean instance type=CacheManager,name="SampleCacheManager" already registered under 'org.infinispan' JMX domain. If you want to allow multiple instances configured with same JMX domain enable 'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element
at org.infinispan.jmx.JmxUtil.buildJmxDomain(JmxUtil.java:52)
at org.infinispan.jmx.CacheManagerJmxRegistration.updateDomain(CacheManagerJmxRegistration.java:79)
at org.infinispan.jmx.CacheManagerJmxRegistration.buildRegistrar(CacheManagerJmxRegistration.java:73)
at org.infinispan.jmx.AbstractJmxRegistration.registerMBeans(AbstractJmxRegistration.java:37)
at org.infinispan.jmx.CacheManagerJmxRegistration.start(CacheManagerJmxRegistration.java:41)
at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:639)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:300)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:532)
at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:500)
at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:473)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:342)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:472)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:380)
... 93 more

也许我需要某种 infinispan 配置文件,我可以在其中放置

<jmx duplicate-domains="true" />

就像这里提到的那样Infinispan as second level cache hibernate

最佳答案

您应该检查 EAP 7 文档,因为获得二级缓存(由 Infinispan 在幕后提供支持)所需的所有配置如下:

<persistence-unit name="...">
(...) <!-- other configuration -->
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
</properties>
</persistence-unit>

https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.1/html/development_guide/java_persistence_api_jpa#second_level_caches

关于java - JBoss EAP 7 和 Ifinispan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47814316/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com