• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!