Environment
- Two stateless EJBs with their Remote Interfaces. EJB1 is injected into EJB2.
/// EJB1
package com.xxx.layer1;
@Remote
public interface EJB1Remote {
}
@Stateless (mappedNamed="com.xxx.EJB1")
public class EJB1 implements EJB1Remote {
}
/// EJB2
package com.xxx.layer2;
import com.xxx.layer1;
@Remote
public interface EJB2Remote {
}
@Stateless (mappedNamed="com.xxx.EJB2")
public class EJB2 implements EJB2Remote {
@EJB(mappedNamed="com.xxx.EJB1")
EJB1Remote ejb1;
}
-
EJB2 also uses some Optional Packages (declared in its MANIFEST)
-
WebLogic application server (10.3.3)
-
Two EJBs are packaged into two separate JAR files
Problem
If two JAR files are packaged into an EAR file and deployed, dependency injection works. But if I deploy them separately, even though after I deployed EJB1 first and verified the global JNDI name in Weblogic (com.xxx.EJB1#com.xxx.layer1.EJB1Remote), EJB2’s deployment fails with ClassNotFoundException: com.xxx.layer1.EJB1Remote
Each individual JAR file in this case is an application of its own in WebLogic and each application has its own classloader. So when JAR files are deployed separately (not bundled in an EAR file), their classloader doesn’t see the classes inside the others.
In this case, I separated EJB2’s interface into another JAR file and deployed it as an Optional Package and added its reference to other JAR files’ Manifests.