users@glassfish.java.net

Re: _at_Inject + _at_ManagedBean vs _at_EJB

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 17 Dec 2009 09:51:50 +0100

On Dec 17, 2009, at 9:22 AM, Alexis Moussine-Pouchkine wrote:

> Do you mean @javax.annotation.ManagedBean or JSF ?
> If it's the latter you should use @Resource to inject another
> managed bean or keep @EJB if it's an EJB.
> If you want to use JSR 299 (CDI), you should use @Named instead of
> @ManagedBean.


IIUC @Named is a special qualifier associated with types of references
to be injected e.g.:

   @Inject @Named("driver") Seat driverSeat;

@ManagedBean should be redundant if CDI is enabled, by including an
empty beans.xml in the WEB-INF directory. The application did not
produce a binding error at deployment for @Inject of
MemberListService, so i am guess that CDI might not have been enabled.

I cannot recall the details of how one can use @Inject to obtain a
reference to an EJB. Ken would definitely know.


> I'll admit I haven't looked into the that part of the tutorial yet,
> you should look at the weld-servlet and weld-guess samples that you
> can get straight from the GlassFish update center.
>
> -Alexis
>
> On Dec 16, 2009, at 23:28, Dominik Dorn wrote:
>
>> Hi,
>>
>> I want my app to be portable with other frameworks (mainly spring
>> 3.0) and thought

JSR 330, which defines @Inject, might get you some of the way but it
does not define a portable binding. Hence why JSR 299 is required
which also specifies scopes and bindings. The annotations
@ApplcationScoped and @RequestScoped are part of JSR 299 and not JSR
330.

Paul.