I use a JBoss server to host my EJB.
The server is started, I see the main page when I go to localhost:8080 (Welcome to AS 7, Your JBoss Application Server 7 is running.)
On my client project, I try to connect like this :
private static Calculette lookupRemoteStatelessCalculator() throws NamingException {
final Context context = new InitialContext();
context.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
context.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
context.addToEnvironment("java.naming.provider.url", "localhost:8080");
return (Calculette) context.lookup("ejb/stateless/calculette");
}
I go this error message when I run it :
Could not obtain connection to any of these urls: localhost:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server localhost:8080 [Root exception is java.io.EOFException]]
I try with a jndi.properties but I got error I don't understand, when I put the parameter directly on the context it's ok ..
Any idea ?
Thanks
The JNDI lookup works on a different port. By default you will have to use:
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
// create a context passing these properties
Context context = new InitialContext(jndiProps);
Be aware, that for different JBoss/Wildfly versions different approaches exists.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.