Deploying EJB3.0 Beans in JSF2.0 Beans Support ... Impossible?

I am working on a JSF project on Weblogic 11g, and our initial project calls for support for JSF Beans to invoke EJB3.0 Beans to make business logic calls and data access. The @EJB annotation does not seem to work in my project when I try to insert an EJB link to a bean backup. Whenever I get into the class I'm testing, the constructor for my EJB is never called, and I get NPE. Is it possible to insert an EJB3.0 bean in support of the JSF bean? Is there any other way that I should reference the EJB via the JSF Backing bean? What is the best practice?

+4
source share
5 answers

Turns out this is a particular Weblogic problem when deploying something using JSF and EJB. I found this post on Oracle forums that explains how to get @EJB injection working in JSF Managed Beans using Weblogic 11g:

EJB3.0 Injection into JSF managed beans

UPDATE:

After spinning my wheels too short, I have to give up trying to insert an EJB into the JSF ManagedBean on Weblogic 11g. Seems to work great on Tomcat. Perhaps the implementation of EJB3 and JSF will be better in 12G ...

+3
source

I googled and it really looks like a known issue with Weblogic. Many similar topics remain unanswered.

I found this blog that confirms that @EJB on Weblogic only works for resources defined by web.xml and not JSF. The blog also details the workaround using ServletContextListener , which is an IMO, not much better than using JNDI.

I also found this OTN section that confirms that @EJB in Weblogic started working when EJB modules are not included in subdirectories (see answer posted below, February 15, 2011 17:44).

+4
source

To do this, you need to follow two steps:

  • Expand jsf-2.0.war as LIBRARY, you can find it / ORACLE _HOME / wlserver_10.3 / common / deployable-libraries

enter image description here

  1. In your web project, add a link to the jsf-2.0.war library in WEB-INF / weblogic.xml

      <?xml version="1.0" encoding="UTF-8"?> <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd"> <wls:weblogic-version>10.3.3</wls:weblogic-version> <wls:context-root>your_context_app</wls:context-root> <wls:library-ref> <wls:library-name>jsf</wls:library-name> <wls:specification-version>2.0</wls:specification-version> <wls:implementation-version>1.0.0.0_2-0-2</wls:implementation-version> <wls:exact-match>true</wls:exact-match> </wls:library-ref> </wls:weblogic-web-app> 

I have successfully tested this in weblogic 10.3.3 and 10.3.5. If somehow this does not work, try deploying the application as part of the EAR file.

+2
source

So here is the beat! There is an easy way to fix this.

  • Open jsf-2.0.war under ... wlserver_10.3 \ common \ deployable-libraries

  • Go to WEB-INF / lib and save the wls.jsf.di.jar JAR somewhere

  • Place the wls.jsf.di.jar JAR in the lib folder of your WAR application.

  • Deployment

everything should work now by simply adding @EJB to the property in @ManagedBean.

+1
source

There is an alternative to @EJB annotation to get the local EJB bean available in your JASF ManagedBean web application. Given that you have EJB classes and your WAR packaged in the same EAR file, follow these steps:

  • configure ejb-jar.xml to tell weblogic about exporting EJB beans to external components;

     <enterprise-beans> <session> <ejb-name>MyEJBBean</ejb-name> <business-local>com.app.MyEJBBeanLocalInterface</business-local> <ejb-class>com.app.MyEJBBeanLocalImpl</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> <ejb-local-ref> <ejb-ref-name>ejb/MyEJBBeanLocal</ejb-ref-name> <local>com.app.MyEJBBeanLocalInterface</local> </ejb-local-ref> </session> <enterprise-beans> 
  • Paste the EJB link into the web.xml of your web application using the name of the ejb link. The name ejb-ref-name is visible to JSF managed beans.

     <ejb-local-ref> <ejb-ref-name>ejb/MyEJBBeanLocal</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>com.app.MyEJBBeanLocalInterface</local> <ejb-link>MyEJBBean</ejb-link> </ejb-local-ref> 
  • In the JSF Managed Bean, invoke the EJB bean through a JNDI lookup as follows:

     try { Context context = new InitialContext(); MyEJBBeanLocalInterface myEJBBean = context.lookup("java:comp/env/ejb/MyEJBBeanLocal"); } catch (NamingException e) { e.printStackTrace(); } 

In my case, I used Weblogic 10.3.6 (11g), JSF 2.0 and EJB 3.0 with JPA (Eclipselink)

+1
source

All Articles