• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Injection of EJB in POJO class not working..

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am trying to inject Stateless session bean in POJO(non-EJB) class using @EJB annotation but I am getting NPE exception but same is working inside EJB.

So my question is can we inject EJB inside POJOs?

THanks,
Yash
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

i have a similar problem since I am trying to inject a ConnectionFactory using @Resource annotation, but I am getting null result (no error, just my object is null).
I am trying this in a jsf managed bean. Is this possible or do I have to do it in another way?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Panos,
Welcome to CodeRanch! What version of JEE are you using? (Injecting into a managed bean should work in the latest version.)
 
Panos Gouleas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eclipse Helios with jdk 1.6
Jboss 6 final
JSF 2.0
 
Ranch Hand
Posts: 109
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Panos,

You have to add your EJB servers library files and JavaEE API libraries into your projects library directory to run that program outside from the EJB server.
But I suggest to use JNDI lookup for get server side instance if your client program runs outside from the EJB server.
 
Greenhorn
Posts: 26
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Injection of an enterprise bean in a non-managed POJO is not possible.

If you're trying for something say

@EJB
private SampleSessionLocal sessionLocal;


in a simple java class, which comes after your servlet takes the input from the client,
then the container would obviously throw a Null Pointer Exception.

As far as I know, an enterprise bean can be injected into the following managed java objects:
1. Another Enterprise Bean ( EJB 2 or EJB 3 compatible).
2. A Servlet
3. JSF class.

I am not sure about the JSF thing, but the first two things are for sure.

Regards,
Akshay Sahu
 
reply
    Bookmark Topic Watch Topic
  • New Topic