Reputation: 324355
I'm having trouble using dependency injection (with CDI/Weld) within libraries used in a war when deploying on Glassfish 3.1. I have two libraries, say:
WEB-INF/lib/library1.jar
WEB-INF/lib/library2.jar
library1 contains a public class, say "InjectMe". Library2 contains another public class, say "InjectionTarget" with an injection site like "@Inject public InjectMe injectMe;" .
Deployment fails with:
WELD-001408 Unsatisfied dependencies for type [InjectMe] with qualifiers [@Default] at injection point [[field] @Inject packagename.InjectionTarget.injectionSite].
Both archives are valid CDI archives with a META-INF/beans.xml .
I've updated weld-osgi-bundle.jar in Glassfish 3.1 and still see the issue.
If I manually unpack library1 and library2, putting their classes directly into WEB-INF/classes, deployment succeeds and injection works as expected.
This is rapidly driving me completely insane. I'm on the verge of restructuring my modules so that the jar subpackages are unpacked with maven-dependency-plugin and archived as a merged jar that I then depend on from my war. That's pretty gruesome, though.
Ideas? Shouldn't this "just work"?
Upvotes: 4
Views: 2796
Reputation: 324355
This turned out to be PEBKAC error. I'd updated weld-osgi-bundle.jar on my desktop and workstation but not laptop, but thought I'd updated it on the laptop too.
If you're reading this you probably have a similar issue. Check your weld-osgi-bundle version with:
asadmin list-modules | grep org.jboss.weld.osgi-bundle
(Windows users: use findstr instead of grep, but the command is otherwise unchanged).
You should get the result:
Module : org.jboss.weld.osgi-bundle:1.1.1.Final
If you see an older version, update weld-osgi-bundle according to the instructions here:
http://seamframework.org/Seam3/CompatibilityHome#H-UpgradingWeldInGlassFish31
These instructions apply even if you don't use Seam. Weld 1.1.1 fixes several significant bugs in CDI. It's beyond me why a Glassfish 3.1.2 hasn't been released with it, because they're important fixes.
Upvotes: 4
Reputation: 2552
Maybe you are running into this bug?
https://issues.jboss.org/browse/WELD-846
http://java.net/jira/browse/GLASSFISH-15721
http://java.net/jira/browse/GLASSFISH-15735
I think Glassfish 3.1.1-b04 and newer use Weld 1.1.1.Final which is marked as the fix version for the underlying Weld bug. Testing with that exact version might be enough to confirm it.
Upvotes: 3