cachingwildflyinfinispanwildfly-26

WIldfly 26 Infinispan cache usage inside Java application problem


I was migrating Java application from JavaEE7 and Wildfly 8 to JakartaEE8 and Wildfly 26, but after making all changes Infinispan cache stopped to work.

On Wildfly Admin UI I see correctly cache container and cache definitions, but inside application cache is not visible. Cache container I'm able to fetch using JNDI name, but inside this cache container there is no cache objects. And when I try to getCache() I receive an error:

org.infinispan.commons.CacheConfigurationException: ISPN000436: Cache 'cachedb' has been requested, but no matching cache configuration exists

Here is cache container definition from Widfly configuration

<cache-container name="reporting-cache" default-cache="cachedb">
    <transport lock-timeout="60001"/>
    <replicated-cache name="cachedb">
         <transaction mode="BATCH"/>
    </replicated-cache>
</cache-container>

And how I try to fetch it

@Resource(lookup = "java:jboss/infinispan/container/reporting-cache")
CacheContainer cc;

Cache<String, String> cache;

@PostConstruct
void init() {
    this.cache = cc.getCache();
}

What can be wrong after migration from old Wildfly to Wildfly 26?


Solution

  • Solved this issue when added these lines to web.xml file

    <resource-ref>
        <res-ref-name>reporting-cache/default</res-ref-name>
        <lookup-name>java:jboss/infinispan/cache/reporting-cache/default</lookup-name>
    </resource-ref>
    

    And it doesn't matter if in your code you'll use injection to CacheContainer using

    @Resource(lookup = "java:jboss/infinispan/container/reporting-cache")
    CacheContainer cc;
    

    or injecting to Cache directly using

    @Resource(lookup = "reporting-cache/default")
    Cache<String, String> cache;
    

    Everything works in both ways