I am a beginner in EJB 3.1 and trying to run my first Hello World program and getting the NameNotFoundException.
Exception in thread "main" javax.naming.NameNotFoundException: WFNAM00004: Name "global/HelloWorld/HelloWorldBean!api.HelloWorldRemote" is not found
at org.wildfly.naming.client.util.NamingUtils$1.lookupNative(NamingUtils.java:95)
at org.wildfly.naming.client.AbstractContext.lookup(AbstractContext.java:84)
at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:150)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at driver.HelloWorld.main(HelloWorld.java:27)
Here are my classes
Local Interface:
@Local
public interface HelloWorldLocal {
public void getHello();
}
Remote Interface:
@Remote
public interface HelloWorldRemote extends HelloWorldLocal {
}
Bean Class:
@Stateless(name="HelloWroldBean")
public class HelloWorldBean implements HelloWorldLocal, HelloWorldRemote{
@Override
public void getHello() {
System.out.println("Hello Cheppura");
}
}
Client:
public class HelloWorld {
public static void main(String[] args) throws NamingException {
final Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.wildfly.naming.client.WildFlyInitialContextFactory");
Context con = new InitialContext(jndiProperties);
final String appName = "";
final String moduleName = "HelloWorld";
final String beanName = HelloWorldBean.class.getSimpleName();
final String viewClassName = HelloWorldRemote.class.getName();
Object ob = con.lookup("java:global" + appName + "/" + moduleName + "/" + beanName + "!" + viewClassName);
HelloWorldRemote hw = (HelloWorldRemote) PortableRemoteObject.narrow(ob, HelloWorldRemote.class);
hw.getHello();
}
}
Can anyone please advice on this? Thanks in advance
con.lookup
looks for registered beans, but there's nothing telling WildFly to create an instance ofHelloWorldBean
. – Yserbius