• Post Reply Bookmark Topic Watch Topic
  • New Topic

why resource injection is not allowed in web client for EJB 3.0?

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any particular reason for not allowing resource injection for EJB 3.0 in web client???

Can we have a separate class (POJO) which access EJB 3.0 through resource injection and call it from servlet (web client). Will this be allowed??? The POJO is deployed on web server only like servlet.

Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ankur rathi:
Can we have a separate class (POJO) which access EJB 3.0 through resource injection

No. POJOs are not allowed to have resources injected per the spec. You can do a JNDI lookup. Or you can have the servlet inject the resources and pass them to the POJO. I lean towards the former.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:

Or you can have the servlet inject the resources and pass them to the POJO. I lean towards the former.


It seems that resource injection is not allowed in web client...

http://java.sun.com/javaee/5/docs/tutorial/doc/bnbnp.html
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankur,
That link uses a JSP as a sample, not a servlet. I agree that resources can't be injected into a JSP. Which shouldn't be a problem as it is bad practice for a JSP to have code. A servlet can have resources injected as demonstrated here.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Ankur,
That link uses a JSP as a sample, not a servlet. I agree that resources can't be injected into a JSP. Which shouldn't be a problem as it is bad practice for a JSP to have code. A servlet can have resources injected as demonstrated here.


Thanks Jeanne.

Please have a look at this thread: http://www.coderanch.com/t/156191/java-Architect-SCEA/certification/Obsolete-Design-Patterns-EJB-SCEA, which is causing my confusion.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quotes from that thread:
You can inject EJBs or any resource into servlets

Oh yes you can inject EJBs into servlets, see OpenEJB or JBoss Embedded and pretty soon the embedded Glassfish EJB containers. You can argue that it's non-standard, but it's not against the EJB 3 specs per se.

I am Ok with injecting EJBs in Servlets

The key point was doubt in injecting (see the part I quoted above) stateful session beans in Servlets.


I agree with all of these: it is ok to inject resources into servlets. I agree it doesn't make sense to inject a stateful session bean. That particular scenario didn't come up in this thread though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!