Java 我的代码中的 JNDI 名称在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9739463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the JNDI name in my code?
提问by Rohit Elayathu
I have created a EJB2.0 using Eclipse 3.7 IDE, and deployed it in JBoss 5 application server (my bean name is product). I am doing normal context lookup (and other stuff to call ejb), and I am able to call EJB successfully. Now my question is what is JNDI name exactly, and where did it get used in all this. Is my bean name the JNDI name, or is this my JNDI name -> org.jnp.interfaces.NamingContextFactory
. Where is the JNDI name in this?????
my code:-
我已经使用 Eclipse 3.7 IDE 创建了一个 EJB2.0,并将其部署在 JBoss 5 应用服务器中(我的 bean 名称是产品)。我正在做普通的上下文查找(和其他调用 ejb 的东西),并且我能够成功调用 EJB。现在我的问题是 JNDI 名称究竟是什么,以及它在所有这些中的使用位置。我的 bean 名称是 JNDI 名称,还是我的 JNDI 名称 -> org.jnp.interfaces.NamingContextFactory
。JNDI 名称在哪里????我的代码:-
// initial code.............
Context ctx = getContext();
Object obj=ctx.lookup("Product");
ProductHome home =(ProductHome) javax.rmi.PortableRemoteObject.narrow(obj,ProductHome.class);
ProductRemote remote=home.create();
Product prd = new rohit.Product("PRDCamera",001,50.50) ;
remote.addProduct(prd);
remote.updateProduct(prd);
remote.removeProduct(001);
remote.findProduct(001);
remote.findAllProduct();
// getContext Method
public static InitialContext getContext() throws Exception{
Properties pro = new Properties();
pro.put(javax.naming.InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
pro.put(javax.naming.InitialContext.PROVIDER_URL,"localhost:1099");
return new InitialContext(pro);
}
采纳答案by Ingo Kegel
There is no JNDI name in your code.
您的代码中没有 JNDI 名称。
This is how you look up EJBs in EJB 2.0:
这是您在 EJB 2.0 中查找 EJB 的方式:
Object ejbHome = initialContext.lookup("java:comp/env/com/mycorp/MyEJB");
MyHome myHome = (MyHome)javax.rmi.PortableRemoteObject.narrow(
(org.omg.CORBA.Object)ejbHome, MyHome.class);
The JNDI name is java:comp/env/com/mycorp/MyEJB
in this case.
java:comp/env/com/mycorp/MyEJB
在这种情况下是 JNDI 名称。
In the much saner EJB 3.0, you just do
在更加理智的 EJB 3.0 中,您只需
MyEJB myEJB = initialContext.lookup("java:comp/env/com/mycorp/MyEJB")
and do away with the terrible home interface idea.
并废除可怕的家庭界面想法。