java EJB 查找的初始上下文属性值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9937314/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:57:52  来源:igfitidea点击:

Initial Context property values for EJB lookup

javajbossejb-3.0jndiinitial-context

提问by h-kach

I am learning basics of EJB 3.0. I have managed to get a sample code up and running. Now I am doing a line by line analysis to have in-depth knowledge. But I am stuck at few lines where there is a lookup to find the required bean.

我正在学习 EJB 3.0 的基础知识。我已经设法启动并运行了一个示例代码。现在我正在逐行分析以深入了解。但是我被困在需要查找所需 bean 的几行中。

Can anyone please explain me in simple language the meaning and the need of the following lines?

谁能用简单的语言向我解释以下几行的含义和需要?

Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");
properties.setProperty(Context.PROVIDER_URL, "localhost:1099");

IniialContext context = null;
SamleEjbRemote cl = null;
try {
    context = new InitialContext(properties);
    cl = (SampleEjbRemote) context.lookup("SampleEjbBean/remote");
} catch (NamingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}


What is the exact meaning of each of the 'key' and 'value' that is used in properties?


属性中使用的每个“键”和“值”的确切含义是什么?

Rest of it is to put the 'properties' in the initial context instance. I have had a very vague idea of the above, but I want to clarify it very clearly. I would be glad if anyone could point me to any links or insights about the above lines.

剩下的就是将“属性”放在初始上下文实例中。上面我有一个很模糊的想法,但我想说的很清楚。如果有人能给我指出有关上述行的任何链接或见解,我会很高兴。

Thanks in advance.

提前致谢。

回答by rkosegi

Both properties configures JBoss JNDI HTTP InitialContext Factory Implementation

这两个属性都配置了 JBoss JNDI HTTP InitialContext 工厂实现

Official document here : http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html

官方文件在这里:http: //docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html

See chapter 3.2.1.2. The HTTP InitialContext Factory Implementation

见第 3.2.1.2 章。HTTP InitialContext 工厂实现

java.naming.factory.initial: The name of the environment property for specifying the initial context factory, which must be org.jboss.naming.HttpNamingContextFactory.

java.naming.factory.initial:指定初始上下文工厂的环境属性名称,必须是org.jboss.naming.HttpNamingContextFactory。

java.naming.factory.url.pkgs: For all JBoss JNDI provider this must be org.jboss.naming:org.jnp.interfaces. This property is essential for locating the jnp: and java: URL context factories of the JBoss JNDI provider.

java.naming.factory.url.pkgs:对于所有 JBoss JNDI 提供者,这必须是 org.jboss.naming:org.jnp.interfaces。这个属性对于定位 JBoss JNDI 提供者的 jnp: 和 java: URL 上下文工厂是必不可少的。

UPDATE:

更新:

I would recommend to use jndi.properties file in your class path

我建议在您的类路径中使用 jndi.properties 文件

### JBossNS properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces