Search code examples
jakarta-eeglassfishjndi

Glassfish, problem obtaining EJB through JNDI


I am trying to obtain a reference to EJB2 from EJB1. EJB2 is deployed separately, but they are both running in the same container. I'm using the following code in EJB1:

Context ctx = new InitialContext();
Connector connector = (Connector) ctx.lookup("java:global/earFile/ejbArtifact/EJB2")

Connector is an interface which is packaged with EJB1. It is implemented by EJB2.

The above snippet will give me following exception message:

$Proxy283 cannot be cast to Connector

What am I missing here?


Solution

  • The problem was that the Connector interface had to be annotated as @Local interface. Now it works.