Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lift with enterprise java beans

I have troubles with deploying lift application with uses enterprise java beans. There's a simple example:

@Stateless
class TestEJB {
 def a = "hello"
}

object TestApi extends XMLApiHelper{
 @EJB
 private var bean:TestEJB = _
 def createTag(a:NodeSeq) = 
 def dispatch: LiftRules.DispatchPF = {
  case Req("test" :: Nil, "", GetRequest) =>
   () => PlainTextResponse( bean.a )
 }
}

There's NullPointerException on line with bean.a, so that means, that the bean haven't been initialized well. Why?

like image 749
ryskajakub Avatar asked Nov 06 '22 10:11

ryskajakub


1 Answers

Not Lift-aware, but @EJB is standardly only available to servlet, filter, context listener, jsf managed beans, ejbs, webbeans and other Java EE components. Note JSP classes, due to their dynamic generation/compilation, are not eligible to use @EJB and have to instead lookup EJBs even though they technically count as a servlet at runtime.

As an alternative to injection you could use lookup. If you are in a Java EE 6 server any java code can lookup the EJB via its standard "java:global" JNDI name.

like image 190
David Blevins Avatar answered Nov 11 '22 06:11

David Blevins