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)
source share