Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Injecting EJB into a JSF web application

 
Bojan Tomic
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bojan Tomic
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Bojan Tomic
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clarifying it!
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic