users@glassfish.java.net

InjectionPoint.getBean() returns null in some JAX-RS/CDI cases

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Fri, 29 Jun 2012 18:52:12 -0400

I have a JAX-RS application. I have split it up in a fashion across a .war
and an .ear that contains that .war.

What I mean is: my resource classes are all located in jar files in the
*.ear application's* lib directory. That means (obviously) they are *not*
in the .war file's lib directory. (The .war file is a ridiculously tiny
stub. I do it this way for packaging concerns.)

I am using a @Produces-annotated method in a producer class to do some CDI
injection, which works fine (provided that the beans.xml is in
WEB-INF/beans.xml in the .war file, and is also NOT present in any of the
JAX-RS jars; that's a separate issue).

During this injection, I log some details about the injection itself.

I noticed while doing this that the InjectionPoint object returns null from
getBean() for my JAX-RS classes.

I am too stupid :-) to know whether that is a valid thing to do in this
case. My suspicion is that this is a bug--shouldn't my resource class be a
valid CDI bean? It meets all the criteria for being a CDI bean according
to the CDI 1.0 specification.

I am all too aware that there are dozens of edge cases where CDI and JAX-RS
and @ManagedBean meet; I suppose this gets added to the pile?

Lastly, it should be noted that an InjectionPoint is totally within its
rights to return null if the injection target is not a member of a CDI
bean. However, this strikes me as a case where null probably should not be
returned.

Best,
Laird

-- 
http://about.me/lairdnelson