File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes @EJB static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "@EJB static" Watch "@EJB static" New topic
Author

@EJB static

Camilo Diaz
Greenhorn

Joined: Sep 03, 2009
Posts: 19
Hello there:

i hope you can help me
does have this line of code any sense?

@EJB
private static myStatelessEJB ;

and..... what does it mean ?


Thanks !

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Camilo Diaz wrote:
@EJB
private static myStatelessEJB ;



Is that a typo? Because, it's not going to compile. As for what it means semantically - it's trying to "inject" an EJB into a member of some class. Even semantically, that injection on a static member is only allowed in application clients and for all other components, the injection of an EJB on static fields isn't allowed.

Ofcourse, whatever i said may not make sense, if you are beginning to learn J2EE or EJBs. So feel free to provide more context about your question


[My Blog] [JavaRanch Journal]
Camilo Diaz
Greenhorn

Joined: Sep 03, 2009
Posts: 19
Thank you for the response (Almost nobody answer my questions).

Well... the thing is that i need to use an instance variable of a certain stateless EJB inside a static method. Something like:

@EJB
private static myStatelessEJB myebj;

private static void myMethod()
{
myebj.doStuff();
}

in runtime the application launch a nullpointer exception.
So.... i dont really know what's going on .
Any help ?
Camilo Diaz
Greenhorn

Joined: Sep 03, 2009
Posts: 19
well... if anyone wants to help me, i figured out that the real problem is how to inject a variable of a local interface (an ejb with the @Local annotation )inside a static method.

Thnks
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3057
    
  38

Camilo Diaz wrote:the thing is that i need to use an instance variable of a certain stateless EJB inside a static method.

Well, what is the importance of that usage?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Camilo Diaz
Greenhorn

Joined: Sep 03, 2009
Posts: 19
i need to call a local interface from a POJO within a static method, but... the lookup is not working (launch a NameNotFoundException), any help ??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @EJB static