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!
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