Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hardik Mehta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hardik,

Please post the contents of the MANIFEST.MF file of count-client-acc.jar
 
Hardik Mehta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the contents:


 
Ray Blue
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Hardik Mehta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic