[jboss-user] [Beginners Corner] - Retrieving EJB Reference - Best practice

sickboy79 do-not-reply at jboss.com
Tue Jan 23 08:58:00 EST 2007


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:
 | -> myejbs.jar (in here are my SessionBeans)
 | -> myWebapp.war

My application.xml:
  |   <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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4005317#4005317

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4005317

More information about the jboss-user mailing list