This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 9913
    
158

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: 3011
    
  34

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?


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
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
 
Similar Threads
Static Methods in EJB
EJB
apache/tomcat as an app server
EJB static variables
EJB container - how to initialize a class at server startup ?