我尝试通过开始使用standalone.xml在wildfly 14的应用程序中使用infinispan。
在这种情况下,当使用如下所述的standalone-ha.xml / standalone-full-ha.xml启动时,它可以正常工作。


./standalone.sh -server-config = standalone-ha.xml


但是,当我尝试使用standalone.xml启动它时,在部署它时,我从infinispan遇到错误。

造成这种情况的可能原因是什么,以及如何克服它。 (我已经尝试将resource-ref / resource-env-ref添加到jobs-web.xml / web.xml中)

注意 :

如下所述,将CacheManager注入其客户端

@EJB
CacheManager cacheManager;


堆栈跟踪 :

23:23:31,323 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-7) WFLYEJB0473: JNDI bindings for session bean named 'CacheManager' in deployment unit 'deployment "infinispan-invoker.war"' are as follows:

    java:global/application/CacheManager!infnispan.CacheManager
    java:app/application/CacheManager!infnispan.CacheManager
    java:module/CacheManager!infnispan.CacheManager
    ejb:application/CacheManager!infnispan.CacheManager
    java:global/application/CacheManager
    java:app/application/CacheManager
    java:module/CacheManager

23:23:31,530 INFO  [org.jboss.weld.Version] (MSC service thread 1-7) WELD-000900: 3.0.5 (Final)
23:23:31,755 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-3) ISPN000128: Infinispan version: Infinispan 'Estrella Galicia' 9.3.1.Final
23:23:31,979 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 72) WFLYCLINF0002: Started client-mappings cache from ejb container
23:23:32,155 INFO  [org.jboss.weld.Bootstrap] (Weld Thread Pool -- 3) WELD-001125: Illegal bean type javax.ws.rs.ext.MessageBodyReader<java.util.Map<?, ?>> ignored on [EnhancedAnnotatedTypeImpl] public @ApplicationScoped @Provider @Consumes class org.jboss.resteasy.plugins.providers.multipart.MapMultipartFormDataReader
23:23:32,155 INFO  [org.jboss.weld.Bootstrap] (Weld Thread Pool -- 5) WELD-001125: Illegal bean type javax.ws.rs.ext.MessageBodyReader<java.util.List<?>> ignored on [EnhancedAnnotatedTypeImpl] public @ApplicationScoped @Provider @Consumes class org.jboss.resteasy.plugins.providers.multipart.ListMultipartReader
23:23:32,388 INFO  [stdout] (ServerService Thread Pool -- 72) cacheContainer : server
23:23:32,390 INFO  [stdout] (ServerService Thread Pool -- 72) cacheContainer CacheNames : []
23:23:32,399 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 72) MSC000001: Failed to start service jboss.deployment.unit."infinispan-invoker.war".component.CacheManager.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."infinispan-invoker.war".component.CacheManager.START: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:57)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)
    at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
    at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:127)
    at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:141)
    at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54)
    ... 8 more
Caused by: javax.ejb.EJBException: org.infinispan.commons.CacheConfigurationException: ISPN000436: Cache 'default' has been requested, but no cache configuration exists with that name and no default cache has been set for this container
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:246)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:388)
    at org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:68)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:60)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3.component.singleton.StartupCountDownInterceptor.processInvocation(StartupCountDownInterceptor.java:25)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
    ... 13 more


CacheManager.java

import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.infinispan.Cache;
import org.infinispan.manager.CacheContainer;

@Singleton
@Startup
public class CacheManager {

    @Resource(lookup = "java:jboss/infinispan/container/server")
    private CacheContainer cacheContainer;

    private Cache<String, Object> cache;

    @PostConstruct
    public void init() {
        System.out.println("cacheContainer : " + cacheContainer);
        System.out.println("cacheContainer CacheNames : " + cacheContainer.getCacheNames());
        cache = cacheContainer.getCache("default");
    }

    @PreDestroy
    public void destroy() {
        cacheContainer.stop();
    }

    public void setCache(String key, Object value) {
        cache.put(key, value);
    }

    public Object getCache(String key) {
        return cache.get(key);
    }

    public void setCache(String key, Object value, long expiresIn, TimeUnit timeUnit) {
        cache.put(key, value, expiresIn, timeUnit);
    }

    public void removeCache(String key) {
        cache.remove(key);
    }

    public boolean hasCache(String key) {
        return cache.containsKey(key);
    }

}


standalone.xml

<subsystem xmlns="urn:jboss:domain:infinispan:7.0">
    <cache-container name="server" default-cache="default" module="org.wildfly.clustering.server">
        <local-cache name="default">
            <transaction mode="BATCH"/>
        </local-cache>
    </cache-container>
    <cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">
        <local-cache name="passivation">
            <locking isolation="REPEATABLE_READ"/>
            <transaction mode="BATCH"/>
            <file-store passivation="true" purge="false"/>
        </local-cache>
    </cache-container>
    <cache-container name="ejb" aliases="sfsb" default-cache="passivation" module="org.wildfly.clustering.ejb.infinispan">
        <local-cache name="passivation">
            <locking isolation="REPEATABLE_READ"/>
            <transaction mode="BATCH"/>
            <file-store passivation="true" purge="false"/>
        </local-cache>
    </cache-container>
    <cache-container name="hibernate" module="org.infinispan.hibernate-cache">
        <local-cache name="entity">
            <transaction mode="NON_XA"/>
            <object-memory size="10000"/>
            <expiration max-idle="100000"/>
        </local-cache>
        <local-cache name="local-query">
            <object-memory size="10000"/>
            <expiration max-idle="100000"/>
        </local-cache>
        <local-cache name="timestamps"/>
    </cache-container>
</subsystem>


standalone-ha.xml / standalone-full-ha.xml

<subsystem xmlns="urn:jboss:domain:infinispan:7.0">
    <cache-container name="server" aliases="singleton cluster" default-cache="default" module="org.wildfly.clustering.server">
        <transport lock-timeout="60000"/>
        <replicated-cache name="default">
            <transaction mode="BATCH"/>
            <file-store path="/infinispan/db" passivation="false" preload="true" purge="false"/>
        </replicated-cache>
    </cache-container>
    <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
        <transport lock-timeout="60000"/>
        <distributed-cache name="dist">
            <locking isolation="REPEATABLE_READ"/>
            <transaction mode="BATCH"/>
            <file-store/>
        </distributed-cache>
    </cache-container>
    <cache-container name="ejb" aliases="sfsb" default-cache="dist" module="org.wildfly.clustering.ejb.infinispan">
        <transport lock-timeout="60000"/>
        <distributed-cache name="dist">
            <locking isolation="REPEATABLE_READ"/>
            <transaction mode="BATCH"/>
            <file-store/>
        </distributed-cache>
    </cache-container>
    <cache-container name="hibernate" module="org.infinispan.hibernate-cache">
        <transport lock-timeout="60000"/>
        <local-cache name="local-query">
            <object-memory size="10000"/>
            <expiration max-idle="100000"/>
        </local-cache>
        <invalidation-cache name="entity">
            <transaction mode="NON_XA"/>
            <object-memory size="10000"/>
            <expiration max-idle="100000"/>
        </invalidation-cache>
        <replicated-cache name="timestamps"/>
    </cache-container>
</subsystem>

最佳答案

我们可以通过添加缓存作为资源来做到这一点,如下所示。

@Resource(lookup = "java:jboss/infinispan/cache/server/default")
private Cache<String, Object> cache;

08-04 02:39