Reputation: 41
I want to make a EJB project USE Intellij IDEA.But there was a wrong on it.My project has tow model in a project,One is server and the other is client.I want to start server and run client to execute a sayHello function,but get failed.
My SessionBean Interface And Client Interface
package com.ejb;
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
public String sayHello(String world);
}
My SessionBean Class
import com.ejb.HelloWorld;
import javax.ejb.Stateless;
@Stateless(name = "HelloWorldEJB")
public class HelloWorldBean implements HelloWorld {
public HelloWorldBean() {
}
@Override
public String sayHello(String world) {
return "hello"+world;
}
}
My client Class
package com.ejb;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;
public class HelloWorldClient {
private static HelloWorld lookupRemoteStatelessEjbBean() throws NamingException {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put("jboss.naming.client.ejb.context", true);
final Context context = new InitialContext(jndiProperties);
String namespace="ejb:/EJBServer_war_exploded/HelloWorldEJB!com.ejb.HelloWorld";
return (HelloWorld) context.lookup(namespace);
}
public static void main(String[] args) throws NamingException {
HelloWorld helloWorld = lookupRemoteStatelessEjbBean();
System.out.println(helloWorld);
String s = helloWorld.sayHello("world");
System.out.println(s);
}
}
My properties(this properties has put in src folder exactly)
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=admin
remote.connection.default.password=123456
First I start server and intellij IDEA automatically put war folder into JBOSS(WildFly) 11.I visited EJB amdin website,and war folder exactly in server. The error code is
Exception in thread "main" javax.ejb.NoSuchEJBException: EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/EJBServer_war_exploded/HelloWorldEJB", view is interface com.ejb.HelloWorld, affinity is None
I don't know how to solve it,and I had searched on bing and google.No one had the same question,how can I solve it?
Upvotes: 4
Views: 10665
Reputation: 81
For WildFly11 use the following configuration:
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory"); jndiProperties.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
instead of:
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); jndiProperties.put("jboss.naming.client.ejb.context", true);
Upvotes: 5
Reputation: 21
as far as i'm concerned, replace String
namespace="ejb:/EJBServer_war_exploded/HelloWorldEJB!com.ejb.HelloWorld";
with String
namespace="ejb:/EJBServer_war_exploded/HelloWorldBean!com.ejb.HelloWorld";
Upvotes: 2