• 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

Calling EJB3.0 Bean gives 'java.lang.NullPointerException'

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wondering if anyone could explain why the beloe bit of code works when called from within a Servlet but nit from within a Standard Bean?
I'm just trying to move the code away from the Servlet layer and put it directly into a Bean but I get a 'java.lang.NullPointerException' instead.



As I say, this works from within a Servlet, but if I put it in a Bean it does not.

Any advice?
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think I've sorted it.

Injection in the Servlet then passing the 'local' param over to the Bean.



Can Injection only take lace in certain cases is Servlets?
If so, what's the reason for this? It seems a strange limitation, is there some sort of security reason for this?
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keith,

@EJB only works for components that the container recognizes such as Servlets, EJBs and JSF backing beans. You can use Seam, Spring or Guice to inject EJBs into POJOs that aren't these, but even then the POJO would have to be registered with those "containers" as well. WebBeans gets around this problem in Java EE 6 by just scanning for any recognized annotations in any Java class in the classpath, but the spec doesn't have any production-ready implementations yet.

Hope this helps,
Reza
reply
    Bookmark Topic Watch Topic
  • New Topic