Jacek,
1) I am using jdk1.5.0_12

2) My source code, specifically the definition of CompanyAdminLocal, CompanyAdminReport, and CompanyAdminImpl match the injection example.

3) I did not find an example where the test class used DI to get the EJB. All of the tests got an EJB via context.lookup.

Paul Spencer



Jacek Laskowski wrote:
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


Reply via email to