2 Replies Latest reply on Feb 3, 2007 12:19 PM by sickboy79

    Retrieving EJB Reference - Best practice

    sickboy79

      Hi.

      I have problems connecting to my successful deployed EJB3 SessionBeans from within a web application. If I try it with a standalone J2SE Client App everything works fine.

      If I do the following I get a ClassCastException in my Web Application, in the J2SE Client App this works fine.

      Context context = new javax.naming.InitialContext();
      Object ref = context.lookup("myApp/MyRemoteBean/remote");
      MyRemoteInterface dm = (MyRemoteInterface)ref;


      What am I doing wrong? Btw. What is the best practice to connect to an EJB3 Bean from a WebApp? Is there a way to obtain a reference through dependency injection?

      Here my setup:
      myApp.ear
      | -> myejbs.jar (in here are my SessionBeans)
      | -> myWebapp.war

      My application.xml:
      <application>
       <display-name>my_ejb</display-name>
       <module>
       <ejb>myejbs.jar</ejb>
       </module>
       <module>
       <web>
       <web-uri>myWebapp.war</web-uri>
       <context-root>/myWebApp</context-root>
       </web>
       </module>
      </application>


      Thanks in advance
      Tobias


        • 1. Re: Retrieving EJB Reference - Best practice
          andstall

          This happened to me in the padt because only one of my web application and my ejb application was redeployed, and therefore used incompatible classloaders.

          You can check if this is your case by doing:

          System.out.println(ref.getClass().getClassLoader());
          System.out.println(MyRemoteInterface class.getClassLoader());
          


          If you get different classloaders then that is it.
          (Remember classes loaded by different class loaders are incompatible).
          What you must do is to redeploy both the web and the ejb application together, and not only one of them.
          Or restart jboss, which takes more time.
          Tell me if this helps.

          • 2. Re: Retrieving EJB Reference - Best practice
            sickboy79

            Thanks for your response. After some additional research i found out the the Web Installer of Jboss AS 4.0.5 installs EJB 3 RC4. After manually updating to RC9 it worked correctly.

            Eitherway the tip from andstall helped me a lot. This really sometimes aids me in resolving classloading errors.