我想知道如何使用JNDI从远程客户端查找位于WildFly服务器中的EJB。
以下是我用来初始化上下文的内容
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://192.168.0.15:8080");
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);
这是我部署服务器时的控制台输出:
21:08:29,352 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-10) JNDI bindings for session bean named DataBaseServiceImpl in deployment unit deployment "AnalyseExcelServeur.war" are as follows:
java:global/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService
java:app/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService
java:module/DataBaseServiceImpl!serveur.database.DataBaseService
java:jboss/exported/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService
java:global/AnalyseExcelServeur/DataBaseServiceImpl
java:app/AnalyseExcelServeur/DataBaseServiceImpl
java:module/DataBaseServiceImpl
我尝试了很多组合,但每次得到javax.naming.NameNotFoundException:
javax.naming.NameNotFoundException: exported/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService -- service jboss.naming.context.java.jboss.exported.exported.AnalyseExcelServeur."DataBaseServiceImpl!serveur.database.DataBaseService"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我没有定义应用名称或模块名称。
以下是我如何声明EJB:
@Stateless
@Remote(DataBaseService.class)
public class DataBaseServiceImpl extends SessionDB implements DataBaseService
在客户端,DataBaseService接口的实现位于包compte.remote.ejb
中我不知道是否必须使用ejb:/ appname / modulename / bean / location 或者只是/ appname / modulename / bean / location或其他任何东西......
也许我必须将一个文件放入.war来声明EJB ...
答案 0 :(得分:1)
也许你应该看看文档:
https://docs.jboss.org/author/display/WFLY8/EJB+invocations+from+a+remote+client+using+JNDI
答案 1 :(得分:0)
希望这可能有助于解决问题。 (它用于查找JMS队列,但也可以用于Beans的相同方式。)
http://www.mastertheboss.com/jboss-server/jboss-jms/how-to-code-a-remote-jms-client-for-wildfly-8
由于
答案 2 :(得分:0)
我做到了!!问题是我为ejb使用了两个不同的类路径。
服务器端的ejb位于serveur.database.DataBaseService
客户端ejb的接口位于compte.remote.ejb.DataBaseService
它们应该位于相同的路径中,因此我将客户端的ejb重新定位到包名称serveur.database中并且该工作正常!