1

I'm trying to learn EJB3, I created an EJB project with just a bean class:

package com;
import javax.ejb.Local;
import javax.ejb.Stateless;

 @Stateless
 @LocalBean
 public class MyBean {

 public MyBean() {
    // TODO Auto-generated constructor stub
  }
public String getMessage(){
    return "Hello";
  };

}

I deployed this project on Jboss 6 , then i create a Java project (adding in the build path the ejbProject above and Jboss-client.jar to make RMI calls).

for testing , this is the class i created:

  import javax.ejb.EJB;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import com.MyBean;

public class LanceProgram {
 // @EJB
 //public static MyBean mybean;

public static void main(String[] args)  {
    Context ctx;
    try {
        ctx = new InitialContext();
        MyBean exampleBean = (MyBean) ctx.lookup("MyBean");

        System.out.println(exampleBean.getMessage());
    } catch (NamingException e) {

        e.printStackTrace();
    }

  }

 }

Normally, when running this, i should have a reference to MyBean,but it's null and i have this error message (using JNDI lookup):

Exception in thread "main" java.lang.ClassCastException:       org.jnp.interfaces.NamingContext cannot be cast to com.MyBean
at LanceProgram.main(LanceProgram.java:17)

While with an EJB injection i have a NullPointerException !

this i my jndi.properties file specifications:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

I'm trying to make a call to a bean which doesn't implements an interface. Thanks for helping

Alex2330
  • 347
  • 1
  • 7
  • 21
  • You are technically doing a remote call and your ejb is a localbean. Localbeans are local within a module, not within a server nor machine – maress Nov 19 '15 at 07:28
  • Tkanks for your response, i have changed my bean to implement a (AT)Remote interface (My bean is annotated like this:(AT)Stateless(name="MyBean")) and it's work, but when i change the interface annotation to @Local , i have an error:( java.lang.RuntimeException: Could not find proxyfactory at ProxyFactory/TPEJB/MyBean/MyBean/local -looking up local Proxy from Remote JVM?).Any explanations? Thanks.I'm using JNDI lookup. – Alex2330 Nov 19 '15 at 13:44

0 Answers0