File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB client with DI - @EJB injection doesn't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB client with DI - @EJB injection doesn Watch "EJB client with DI - @EJB injection doesn New topic
Author

EJB client with DI - @EJB injection doesn't work

Hardik Mehta
Greenhorn

Joined: Jul 31, 2006
Posts: 19
I am using glassfish V3 container.

I have deployed a very simple stateful EJB which is accessible by a client which uses global jndi lookup. But it is not accessible using the @EJB (DI) method.

Also the commandline described in glassfish documentation and other books is also not working for running the client in the ACC (Application client container).

Here the Client code:


The bean is code is like following:



After deploying the bean in the container. I tried following commandlines to run the client.

1. This is described in glassfish documentation and other online material.


2. This works for me when I run the jndi lookup client.



Am I making some mistake ?

cout << About programming, Linux, music, stars, life and everything;
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10289
    
168

Hardik,

Please post the contents of the MANIFEST.MF file of count-client-acc.jar


[My Blog] [JavaRanch Journal]
Hardik Mehta
Greenhorn

Joined: Jul 31, 2006
Posts: 19
Here the contents:


Ray Blue
Greenhorn

Joined: Jul 12, 2009
Posts: 8
As far as I can see you are trying to DI a stateful session bean. You will have to use lookup instead of injection. Can anyone paste some lookup example, because I have the same problem right now ;) My JNDI lookup works in JBoss but unforunately not in GlassFish. Where is the difference?


SCJP 6.0
Hardik Mehta
Greenhorn

Joined: Jul 31, 2006
Posts: 19
Why shouldn't DI work for stateful beans ? On glassfish forums I was told, may be it is due to the following bug...
https://glassfish.dev.java.net/issues/show_bug.cgi?id=8631
Manuel Alberto Quero
Ranch Hand

Joined: Jul 17, 2009
Posts: 31
Hi Hardik,

I think that the reason why it is not working is because of the way you are using Dependency injection (DI).

DI can only be used by classes which are managed by containers (EJB, servlets), i.e., it is not possible to use DI (@EJB) in your client because it is non-managed.

Morover, DI is intended to "inject" local references (those references obtained from the java:comp/env context) so I don't think you can inject the remote reference of your CountBean.

So to get DI working I think you could try this:
1) Use as a client another EJB or a servlet
2) Define a local interface for your CountBean

Hope this helps,

Manuel
Hardik Mehta
Greenhorn

Joined: Jul 31, 2006
Posts: 19
Thanks Manuel, for the the explanation.

What I forgot to mention in my first post (which I thought would be assumed, my fault) is that I also deploy the client in the container with the bean. This means and it is also written in the book, that it is deployed in the container (Application Client Container) and DI should be available for that client. I followed this documentation to deploy on glassfish.
http://docs.sun.com/app/docs/doc/820-7693/beaem?l=en&a=view&q=application+client


Following the similar documentation for JBOSS here, I could get the same client working.
http://www.jboss.org/community/wiki/HowtouseanapplicationclientinJBoss-5



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB client with DI - @EJB injection doesn't work