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:
Situation
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:
- changed packaging type to ejb for ejb-cdi.jar containing the EJB's and CDI managed beans
- configured ejb-cdi.jar as ejbModule in pom.xml
- configured WAR1 and WAR2 as webModule in pom.xml
- configured the WAR1 and WAR2 as skinny wars without ejb-cdi.jar
- ensured that EJB lookups are succesful by using @Stateless(mappedName="XX") and @EJB(beanName="XX")
Problem
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:
- Add ejb-cdi.jar to the classpath -> EJB's are now ambiguously defined
- Make ejb-cdi.jar a regular JAR again -> EJB lookups fail entirely
- Add ejb-cdi.jar with a different classifier extra to /lib -> EJB's are now ambiguously defined
(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?