1

I use Wildfly 17 and have a couple of stateless EJBs, one of which causes me sometimes ( but not always) problems upon JNDI lookup. This is my EJB:

@Stateless
public class AVeDBService {
  //other stuff here
}

When I deploy my application I see the following log for the above service:

java:global/heimdi/AVeDBService!at.home.digest.services.AVeDBService
java:app/heimdi/AVeDBService!at.home.digest.services.AVeDBService
java:module/AVeDBService!at.home.digest.services.AVeDBService
ejb:/heimdi/AVeDBService!at.home.digest.services.AVeDBService
java:global/heimdi/AVeDBService
java:app/heimdi/AVeDBService
java:module/AVeDBService

I have a ServiceLocator class that is a singleton looks up a stub of the above service using the following JNDI name:

    public class ServiceLocator {

     private static final String AVE_DB_SERVICE_JNDI_KEY = 
     "java:global/heimdi/AVeDBService!at.home.digest.services.AVeDBService";

     private Map<String, Object> serviceHolder = new HashMap<String, Object>();

     private ServiceLocator() {
        try {
            Context ctx = new InitialContext();
            AVeDBService aveDBService = (AVeDBService) ctx.lookup(AVE_DB_SERVICE_JNDI_KEY);
            serviceHolder.put(AVE_DB_SERVICE, aveDBService);
          }

     }

}

Now, when I use the Service Locator to obtain a stub to my service, I sometimes get the exception below. But only sometimes:

Caused by: java.lang.ClassCastException: class at.home.digest.services.AVeDBService$$$view39 cannot be cast to class at.home.digest.services.AVeDBService (at.home.digest.services.AVeDBService$$$view39 is in unnamed module of loader 'deployment.heimdi.war' @658d7dca; at.home.digest.services.AVeDBService is in unnamed module of loader 'deployment.heimdi.war' @15cdf490)

I am using my service in the same war. module, in which it is declared (the same web-application). But nevertheless the global lookup should always work, or? Could that be a bug in WildFly 17.0? I could not find an answer in similar related questions, such as:

Portable JNDI Syntax lookup for EJB on Glassfish

what is the difference between jndi binding of module and app in Java ee 6/7?

Cannot be cast to class because they are in unnamed module of loader 'app'

Thank you!

Alex Mi
  • 1,409
  • 2
  • 21
  • 35
  • Did you ever find a solution to this? I'm running into the exact same problem. – pbuchheit Dec 22 '20 at 15:20
  • Actually not. I was told to upgrade the WildFly version, but I never found time to do this. So, the problem still persists on my side. – Alex Mi Dec 22 '20 at 16:15
  • 1
    What version did they recommend? I'm using 18.01.Final and still seeing it. – pbuchheit Dec 22 '20 at 17:51
  • @pbuchheit at the time I asked the question, they recommended the latest version, which was, I think 19 or 20. Do you see the message each time? Cause I saw it only from time to time; In most of the cases, it went OK, without any problems – Alex Mi Dec 23 '20 at 06:44
  • I'm seeing it every time, so I suspect my issue is a misconfiguration on my end somewhere. Do you have a link to where you asked the question at? I would be interested in seeing the details. – pbuchheit Dec 23 '20 at 13:42
  • @pbuchheit I aksed it via an email to the Wildfly users group. I am not sure if I keep this email still, but there were no other clues or details there – Alex Mi Dec 23 '20 at 14:06

2 Answers2

0

I had the same problem when I want to deploy an ear on Wildfly 21. All I had to do to solve this is to change my @Local annotations to @Remote on all my Sessions Bean

massire1
  • 1
  • 1
0

I had same problem with Wildfly 24.1, the problem was the Classloader of the classes in the EAR project, i had to change the dependence of the EJB in the POM of the WAR as provided, so the final EAR only contains one copy of the EJB class, that has solve my problem

POM Example