users@glassfish.java.net

Re: Dependency injection does not work

From: <glassfish_at_javadesktop.org>
Date: Tue, 19 May 2009 07:07:49 PDT

take a look at this thread:

[i][b]injections

Eve,

It's important to note that the Java EE 5 spec specifies that injection take place only in "managed" classes. In the app client, there are only two managed classes: the main class (as specified either in the manifest or on the appclient command line) and the optional log-in callback class.

Also, the spec also mandates that in the app client main class only static elements can be injected.

Here is one general approach that some people find works for them:

1. Define the injected static fields on the app client's main class:

@EJB
private static UsersRemote usersRemote;

2. Write a static accessor method on the app client's main class:
static UserRemote getUserRemote() {
    return usersRemote;
}

3. From anywhere in any of the classes in your app client use Main.getUserRemote() when you need to use the EJB.

- Tim[/b][/i]

Thats how I resolved problems similar to yours.

eve
[Message sent by forum member 'eve2' (eve2)]

http://forums.java.net/jive/thread.jspa?messageID=346789