Infinispan cache container injection in jakarta ee 10 and Wildfly 31.0.0

389 views
Skip to first unread message

Susanne Jarl

unread,
Feb 7, 2024, 7:07:10 PM2/7/24
to WildFly
Hi,
I'm trying to upgrade from java ee 8 and Wildfly 26.1.0 to jakarta ee 10 and Wildfly 31.0.0 but the infinispan cache won't work. I get an exception when I try to inject the cache container in my ejb:

import org.infinispan.manager.CacheContainer;
@Resource(lookup = "java:jboss/infinispan/container/myCache")
private CacheContainer cacheContainer;

The exception:
Caused by: jakarta.ejb.EJBException: java.lang.IllegalArgumentException: WFLYEE0117: Field cacheContainer cannot be set - object of class org.jboss.as.clustering.infinispan.manager.DefaultCacheContainer loaded by ModuleClassLoader for Module "org.jboss.as.clustering.infinispan" version 31.0.0.Final from local module loader @65a15628 (finder: local module finder @2e6a5539 (roots: /myserverpath/wildfly-31.0.0.Final/modules,/myserverpath/wildfly-31.0.0.Final/modules/system/layers/base)) is not assignable to interface org.infinispan.manager.CacheContainer loaded by ModuleClassLoader for Module "deployment.myname.war" from Service Module Loader

The configuration in standalone.xml is
<cache-container name="myCache" default-cache="myCacheDefault">
    <local-cache name="myCacheDefault"/>
</cache-container>


Any ideas? This worked perfectly with java ee 8 and Wildfly 26.1.0.

Many thanks in advance!

Paul Ferraro

unread,
Feb 12, 2024, 3:59:51 PM2/12/24
to WildFly
I suspect the underlying issue is that your deployment was compiled against org.infinispan:infinispan-core, but the server was compiled against org.infinispan:infinispan-core-jakarta
Is that possible?
Also, how are you exposing the Infinispan classes to your application?

Susanne Jarl

unread,
Feb 13, 2024, 12:21:21 AM2/13/24
to WildFly
Hi, thanks for answering!
In my pom I've got the Wildfly 31.0.0 BOM in my depencencyManagement. As dependencies of infinispan I've got the jakarta versions. See below.

<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-ee-with-tools</artifactId>
<version>
31.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-commons-jakarta</artifactId>
</dependency>

If I look at the dependencies in IntelliJ it seems to be the right versions: 

infinspan-dependencies.jpg


Any ideas?
/Susanne

Paul Ferraro

unread,
Feb 13, 2024, 3:33:52 PM2/13/24
to WildFly
Are you bundling these jars in your deployment?  BOM dependencies should always use provided scope so that they are not packaged with your deployment archive.
Instead, the deployment should be configured to import the requisite module provided by the server.
To import the server's infinispan modules into your deployment, you should define the following in your /META-INF/MANIFEST.MF:

Dependencies: org.infinispan, org.infinispan.commons

Susanne Jarl

unread,
Feb 13, 2024, 9:35:43 PM2/13/24
to WildFly
Thank you! Problem is solved!

Only adding (as you suggested):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.infinispan, org.infinispan.commons</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
to the plugins in my pom solved the problem. 😊👍

Although, the infinispan jars were never packaged in my war WEB-INF/lib folder when I had the problem. But when I add the plugin creating the manifest (code above), then I find the inifinspan jars (jakarta versions) in WEB-INF/lib and my problem is solved.

If I change the wildfly bom dependency scope from import to provided I will get a lot of errors like 'dependencies.dependency.version' is missing, when running maven install:
This:
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-ee-builder</artifactId>
<version>
31.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>

Gives:
[ERROR]     'dependencies.dependency.version' for jakarta.enterprise:jakarta.enterprise.cdi-api:jar is missing. @ line 120, column 15
[ERROR]     'dependencies.dependency.version' for org.hibernate.validator:hibernate-validator:jar is missing. @ line 136, column 15
[ERROR]     'dependencies.dependency.version' for org.infinispan:infinispan-core-jakarta:jar is missing. @ line 150, column 15
[ERROR]     'dependencies.dependency.version' for org.infinispan:infinispan-commons-jakarta:jar is missing. @ line 156, column 15
[ERROR]     'dependencies.dependency.version' for org.wildfly.security:wildfly-elytron:jar is missing. @ line 240, column 15
[ERROR]     'dependencies.dependency.version' for jakarta.persistence:jakarta.persistence-api:jar is missing. @ line 287, column 15
[ERROR]     'dependencies.dependency.version' for jakarta.security.enterprise:jakarta.security.enterprise-api:jar is missing. @ line 293, column 15
[ERROR]     'dependencies.dependency.version' for org.slf4j:slf4j-api:jar is missing. @ line 298, column 15


Thank you very much!! 
Susanne

Reply all
Reply to author
Forward
0 new messages