users@glassfish.java.net

Re: CDI's relationship to _at_ManagedBean

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Mon, 11 Jun 2012 14:42:41 -0700

Laird,

ManagedBean is a managed bean. So all injections should work as
expected. We have ejb devtests that inject @EJB into a ManagedBean. I
need to check that all injection points are verified to be not null, but
a quick change to one of the tests (no beans.xml) shows that injected
EJB can be accessed correctly.

HTH,
-marina

Laird Nelson wrote:
> For those not breathlessly
> following http://java.net/jira/browse/GLASSFISH-18793, GlassFish's
> integration between JAX-RS, Managed Beans and CDI is puzzling.
>
> Perhaps it would not be puzzling if there were a clear answer to these
> questions:
>
> Does a class annotated @ManagedBean that is NOT part of a CDI bean
> archive "count" as a potential target for @Injections?
>
> Consider a JAX-RS resource class that is not hosted within its
> "parent" .war file, but is packaged instead inside an .ear file's lib
> directory. Must its "parent" .war file be a bean archive (i.e.
> contain WEB-INF/beans.xml)? (In GlassFish 3.1.2 that .war file must
> be declared as a bean archive for its JAX-RS resource classes that are
> actually packaged apart from it to be valid CDI injection targets--and
> those JAX-RS resource classes must NOT be packaged in bean archives
> themselves; this appears to be a CDI specification violation)?
>
> The CDI specification says in section 1.2.3, about its relationship to
> the Managed Beans specification, that "the container performs
> dependency injection on all managed bean instances, even those which
> are not contextual instances." Which "managed beans" is this area of
> the specification talking about? Java EE Managed Beans? Or CDI
> "managed beans", which include just about everything, provided that
> you're in a bean archive? (In GlassFish 3.1.2 a free-floating JAX-RS
> resource class must NOT be packaged in a bean archive for CDI
> injection to occur, and MUST be annotated @ManagedBean for CDI
> injection to occur. This also appears to be a CDI specification
> violation.)
>
> Hope all this archaeology is helpful to someone.
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>