Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Injecting EJB3.0 Beans into JSF2.0 Backing Beans... Impossible?

I'm working on a JSF project on Weblogic 11g, and our initial design is calling for JSF Backing Beans to invoke EJB3.0 beans to perform business logic and data access calls. The @EJB annotation doesn't seem to work in my project when I try to inject the EJB reference to the backing bean. Whenever I hit the class that I am testing, the constructor for my EJB is never called and I end up with a NPE. Is it possible to inject an EJB3.0 bean into a JSF backing bean? Is there another way I should be invoking an EJB through the JSF Backing bean? What is the best practice?

like image 465
bakoyaro Avatar asked Dec 21 '22 12:12

bakoyaro


2 Answers

I googled somewhat and this indeed seems to be a known issue with Weblogic. Lot of similar topics are kept unanswered.

I found this blog which confirms that @EJB in Weblogic only works for resources definied by web.xml, not for JSF. The blog describes also in detail a workaround using ServletContextListener which is IMO not much better than using JNDI.

I also found this OTN topic which confirms that @EJB in Weblogic started to work when EJB modules are not included in subdirectories (see the answer posted at the bottom, Feb 15, 2011 5:44 PM).

like image 133
BalusC Avatar answered Mar 07 '23 16:03

BalusC


It turns out that it is a Weblogic specific issue when deploying anything using JSF and EJB. I found this post on the Oracle forums that explains how to get the @EJB injection working in JSF Managed Beans using Weblogic 11g:

EJB3.0 Injection into JSF Managed beans

UPDATE:

After spinning my wheels for too long, I have to give up trying to inject an EJB into a JSF ManagedBean on Weblogic 11g. Seems to work fine in Tomcat. Maybe the EJB3 and JSF implementation will be better in 12G...

like image 34
bakoyaro Avatar answered Mar 07 '23 16:03

bakoyaro