I am trying to migrate 2 separate WARs into one EAR.
Running on WebLogic 12.2.1, so Java EE 7 (CDI 1.1 and EJB 3.1).
Each WAR contains the same JAR library containing many @Stateless EJB's and @Named CDI managed beans:
WAR1
|- WEB-INF/lib/ejb-cdi.jar (type=jar)
|- WEB-INF/lib/**.jar
WAR2
|- WEB-INF/lib/ejb-cdi.jar (type=jar)
|- WEB-INF/lib/**.jar
In the old situation the 2 WAR's were deployed separately and everything works fine.
Now, I must package the 2 WAR's into 1 EAR file, which will look something like this:
EAR
|- WAR1.war (skinny, without ejb-cdi.jar)
|- WAR2.war (skinny, without ejb-cdi.jar)
|- ejb-cdi.jar (type=ejb)
|- lib/**.jar
I've performed several required steps:
EJB lookups work and the EAR starts up. During startup all my CDI @Injects fail with the following exception:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied
dependencies for type MyBean with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private my.package.Foo.myBean
After some reading it seems that EJB lookups and CDI injections in EAR files are handled completely different than in plain WAR files.
I assume that since ejb-cdi.jar is not on the classpath in the manifest, the managed beans are not known.
What I have tried:
(I'm hoping I don't have to reorganize the JAR since I've simplified the situation and in practice there are more than 1 such combined jars..)
What would be the best solution to get an EAR where EJB and CDI works correctly?
I the end I understood what went wrong:
Some EJB's and CDI managed beans were in the same ejb-cdi.jar JAR. Some restructuring of the JARs was done, putting all EJB's in one JAR, putting that as ejbModule in /. This ejbModule did not contain any CDI managed beans any more.
The CDI managed beans JARs ended up inside the WAR or in /lib, depending on what the maven-war-plugin with skinnyWar setting decided, but both ways worked.
So, the answer is this:
Reorganize the EJB and CDI managed beans properly, put them in separate JARs and mark the EJB jar as ejbModule.