• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the contents:


 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Message for you sir! I think it is a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic