如何将EJB查询到WildFly服务器到客户端 [英] How to lookup EJB into WildFly server to a client
问题描述
我想知道如何使用JNDI从远程客户端查找位于WildFly服务器中的EJB。
I would like to know how to look up a EJB located into a WildFly server from a remote client using JNDI.
这是我用来初始化上下文
Here is what I use to initialize the context
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);
这是我部署服务器时的控制台输出:
And this is the console output when I deploy the server:
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:
I have try a lot of combination but every time I get a 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)
我还没有定义编辑应用程序名称或模块名称。
I have not defined an app name nor a module name.
- 服务器的项目名称为:AnalyseExcelServeur
- EJB的名称是DataBaseServiceImpl
- EJB实现DataBaseService,它位于包serveur.database中
这是我如何声明EJB:
Here is how I declare the EJB:
@Stateless
@Remote(DataBaseService.class)
public class DataBaseServiceImpl extends SessionDB implements DataBaseService
在客户端实现DataBaseService接口位于包compte.remote.ejb
On the client side the implementation of the DataBaseService interface is located in the package compte.remote.ejb
我不知道我是否必须使用ejb:/ appname / modulename / bean / location
或只是/ appname / modulename / bean / location或其他任何东西...
I don't know if I have to use ejb:/appname/modulename/bean/location or just /appname/modulename/bean/location or anything else...
也许我必须把一个文件放入.war来声明EJB ...
Maybe I have to put a file into the .war to declare the EJB...
推荐答案
我做到了!问题是我为ejb使用了两个不同的类路径。
I did it !! The problem was that i used two different classpath for the ejb.
服务器端的ejb位于serveur.database.DataBaseService
The ejb on server side was in serveur.database.DataBaseService
客户端ejb的接口是在compte.remote.ejb.DataBaseService中
The interface of the ejb on client side was in compte.remote.ejb.DataBaseService
他们应该在同一个路径,所以我重新定位ejb客户端进入一个包名称serveur.database并且工作!
They should be in the same path so i relocate the ejb on client side into a package name serveur.database and that work !
这篇关于如何将EJB查询到WildFly服务器到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!