aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Injecting EJB into a JSF web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Injecting EJB into a JSF web application" Watch "Injecting EJB into a JSF web application" New topic
Author

Injecting EJB into a JSF web application

Bojan Tomic
Greenhorn

Joined: Apr 08, 2008
Posts: 25
If I have an EJB already deployed (on JBoss), and I wish to develop and deploy (to the same app server) a JSF-based web application, what am I supposed to add to my web.xml so that I can use the @EJB annotation to inject EJBs into a managed bean? Is this app server specific?

I hope, you understand my question...

Thanks for your time
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30780
    
157

Veggen,
The J2EE spec doesn't not support injecting EJB into regular Java classes. It supports servlets and other EJBs. For JSF managed beans, you would still need to use a JNDI lookup.

It's possible an app server provides a proprietary way of doing this, but I don't know of one.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bojan Tomic
Greenhorn

Joined: Apr 08, 2008
Posts: 25
Are you sure this applies to Java EE 5 (i.e. JSF 1.2 and EJB 3.0) as well? I'm quite sure I've been seening examples on the web that to this... just not their web.xml and that's the part that troubles me. Of course, I could be wrong.
[ September 14, 2008: Message edited by: Veggen Skrikk ]
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
Yes, there are JEE 5 examples that do this, such as Duke�s Bank, and without anything particular in the web.xml descriptor file.
Bojan Tomic
Greenhorn

Joined: Apr 08, 2008
Posts: 25
Yes, I've seen that example. The only place EJBs are mentioned is in the application.xml within the <module> element. I figured that's because both EJB and Web' app were deployed as a single EAR. So, I was wandering if anything should be added to web.xml if the EJB has already been deployed separately, but it seems the @EJB annotation is itself enough. If someone could confirm, it would be great.

Also, I keep seeing claims that EJB injection into JSF managed beans is not supported on JBoss but it is supported in SunAS/Glassfish, but I've also seen opposite claims... Any info on this would be useful.
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114

Also, I keep seeing claims that EJB injection into JSF managed beans is not supported on JBoss but it is supported in SunAS/Glassfish, but I've also seen opposite claims... Any info on this would be useful.


As far as I know, JBoss uses Tomcat as Webcontainer. Tomcat doesn't implement the @EJB annotation yet, therefore the @EJB doesn't work in JBoss (even with Servlet it doesn't work). You must use JNDI lookup: Example here


Regards, Jair Rillo Junior
http://www.jairrillo.com/blog, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Bojan Tomic
Greenhorn

Joined: Apr 08, 2008
Posts: 25
Thanks for clarifying it!
aleem khan
Ranch Hand

Joined: Aug 07, 2008
Posts: 94
Jboss supports EJB3.0 annotations, infact there is a book by OREILLY which has all the examples based on Jboss 4.x.x and annotations...


SCJP(1.4), SCWCD, Oracle 9i SQL certified, Oracle PLSQL Developer Certified Associate
aleem khan
Ranch Hand

Joined: Aug 07, 2008
Posts: 94
I also suggest all of you to read the book by EJB3.0 in Action by depu panda and then EJB3.0 by OREILLY to understand the correct concepts of EJB3.0 ...
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
Originally posted by aleem khan:
Jboss supports EJB3.0 annotations, infact there is a book by OREILLY which has all the examples based on Jboss 4.x.x and annotations...


JBoss really support EJB3, I did many EJB components on JBoss. You can use @EJB annotation within an EJB component to call another EJB component.
The point here is that you cannot use the @EJB annotation within a Servlet component. It happens because JBoss uses Tomcat as WebContainer and Tomcat doesn't implement that annotation.

Different than Glassfish (or even Geronimo and Websphere) that you can use @EJB annotation within a Servlet component.
sameer ravindra
Greenhorn

Joined: Sep 16, 2008
Posts: 4
i tried on glassfish its working....

i used... private @EJB(name="SessionLocalBean") SessionLocal dao;

@Stateless
public class SessionLocalBean implements SessionLocal


see if it works... gernimo.....and jboss AS 5cr2
[ September 21, 2008: Message edited by: sameer ravindra ]

Sameer Ravindra<br />PA
 
 
subject: Injecting EJB into a JSF web application