On Nov 25, 2007 4:45 AM, Paul Spencer <[EMAIL PROTECTED]> wrote:
> I am trying to test an EJB3 using annotation.  The problem is the
> injected value is always null.

Dependency Injection (DI) in Java EE 5 only works for managed objects
like enterprise javabeans classes or interceptors (limiting it to ejb3
only).

> ***
> * Annotated test class
> ***
> class MyTestClass {
>                 @EJB
>                 CompanyAdminLocal localBean;
>
>                 @EJB(name="CompanyAdminImplRemote")
>                 CompanyAdminRemote remoteBean;
>
>                 @EJB
>                 CompanyAdminImpl defaultBean;

>From EJB3's standpoint the class is not a managed object and cannot
use DI. OpenEJB 3 doesn't even consider it as a target of DI. That's
why the class returns null's from its getters. Make it a ejb (like
@Stateless) with its business interface and it should work fine.

See examples in
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples for
more ejb3 examples. Read about them in
http://openejb.apache.org/examples.html. Let us know when there's no
such an example you're after.

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

Reply via email to