users@glassfish.java.net

Re: Interplay between _at_ManagedBean and CDI?

From: Noah White <emailnbw_at_gmail.com>
Date: Fri, 8 Jun 2012 19:23:18 -0400

Hi Laird,

 I have success using @Inject and @EJB inside my JAX-RS resource classes when I annotate them with @RequestScoped and include an empty beans.xml .. I don't use @ManagedBean

This is all on GF 3.1.2.

-Noah

On Jun 8, 2012, at 4:38 PM, Laird Nelson <ljnelson_at_gmail.com> wrote:

> Oh, CDI and GlassFish: how I have not missed you. :-)
>
> Dredging up an old issue.
>
> Way back in the day we had to use @ManagedBean on our JAX-RS resource classes because CDI injection wasn't working in GlassFish. Specifically, following instructions, we annotated our JAX-RS resource classes with @ManagedBean, and then used @EJB within those resource classes to get references to various EJBs containing business logic.
>
> Now I am at a point where I want to try CDI injection again. I took baby steps this time.
>
> The first step I took was to place beans.xml files in all of our JAX-RS projects' META-INF directories, thus making them all bean archives. I took no other action.
>
> I am now observing that @EJB dependency injection is no longer occurring (the previously correctly injected @EJB-annotated field in a given JAX-RS resource class is now null).
>
> (It may be that perhaps @ManagedBean objects and CDI just cannot coexist, and so perhaps I am violating some specification by simply bringing a beans.xml into the picture.)
>
> Is this a known issue? I would have expected that nothing would have changed except that Weld would be activated, some extra scanning would occur, and that would be about it.
>
> Thanks,
> Laird
>
> --
> http://about.me/lairdnelson
>