简体   繁体   中英

Configure Infinispan in wildfly 14 standalone.xml instead of standalone-ha.xml

I'm try to use infinispan in an application on wildfly 14 by starting using standalone.xml. In this case, when it is started with standalone-ha.xml/ standalone-full-ha.xml as mentioned below it works fine.

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

But when I try to start it using use standalone.xml I'm getting below error from infinispan while it is getting deployed.

What is the possible reason for this and how to overcome it. (I already tried adding resource-ref / resource-env-ref to the jobss-web.xml/web.xml)

Note :

CacheManager is injected to it's client as mentioned below

@EJB 
CacheManager cacheManager;

Stack Trace :

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>

We can do it by adding the cache as resource like below.

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

如果最小配置文件不包含infinispan,则您需要使用正确的配置文件或根据较大的配置文件中的示例添加所需的项目

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM