2 Replies Latest reply on Jul 22, 2008 2:47 AM by jaikiran pai

    Accessing stateless EJB3 bean from a WAR

    Michael Litherland Newbie

      Hi,

      I've searched and read and tried a hundred things, but I'm pulling my hair out on this one. I have a desire to deploy similar, but subtly different EJB projects on a JBoss 4.2.2 application server, then allow my WARs to call those EJB methods using the remote interface. This way for a new customer I deploy a new EJB and the tweaks to the WAR are relatively minor to allow access to the additional EJB project. This seems like it should be straightforward, but I can't overcome a few problems. Here's part of my stateless bean:

      @Stateless
      @RemoteBindings({@RemoteBinding(jndiBinding="custom/remote/MyBean")})
      public class MyBean implements MyBean {
       @PersistenceContext(unitName = "S1-ejbPU")
       private EntityManager em;
       public List<SomeOtherBean> getBeans() {
      ...
      


      My understanding is I need to create an ejb-ref in my web.xml, jboss-web.xml and finally call that from my code (which is a JSF managed bean in this case. First the jboss-web.xml:

      <jboss-web>
      ...
       <ejb-ref>
       <ejb-ref-name>ejb/MyBean</ejb-ref-name>
       <jndi-name>custom/remote/MyBean</jndi-name>
       <!-- also tried this:
       <jndi-name>jnp://localhost:1099/custom/remote/MyBean</jndi-name>
       -->
       </ejb-ref>
      </jboss-web>
      


      The web.xml:

      <web-app ....
      
       <ejb-ref>
       <ejb-ref-name>ejb/MyBean</ejb-ref-name>
       <ejb-ref-type>Session</ejb-ref-type>
       <home/>
       <remote>MyBean</remote>
       </ejb-ref>
      </web-app>
      


      Lastly in the code itself:

       @EJB(name="java:comp/env/ejb/MyBean")
       private MyBeanRemote mbr;
      


      I've tried many variations, but it's not clear to me, even after reading documentation, what all of the various pieces actually do within this processes, nor what I should be calling what. I'd love to see a simplified howto for setting up something like what I desire or suggestions for "better ways" to attempt this.

      Thanks,
      Mike