关于Java:此查找地址在Wildfly 8中是什么意思?

What does this lookup addresses mean in Wildfly 8?

我已经使用Wildfly 8测试了我的第一个sessoin bean。我使用以下代码来获取bean的代理

1
2
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("java:global/EJBDemo/FirstDemoEJB");

当我打印出对象时,得到以下输出

Proxy for remote EJB StatelessEJBLocator{appName='', moduleName='EJBDemo', distinctName='', beanName='FirstDemoEJB', view='interface com.demo.ejb.FirstDemoEJBRemote'}

我可以通过上述查找继续进行RMI,并获得所需的结果。

但是,我发现在部署时,Wildfly还列出了其他查找路径。

1
2
3
4
java:global/EJBDemo/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
java:app/EJBDemo/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
java:module/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote
java:jboss/exported/EJBDemo/FirstDemoEJB!com.demo.ejb.FirstDemoEJBRemote

当我使用其他查找名称名称(在!标记之前的部分)时,得到以下输出

EJBDemo/FirstDemoEJB -- service jboss.naming.context.java.app.TestEJB.EJBDemo.FirstDemoEJB

但是我无法像在java:global lookup中那样获得RMI并获得所需的结果。

我的问题是Wildfly列出的这些其他查找路径是什么意思?它们也可以用于JNDI查找吗?如果可以,该怎么办?


在Java EE 6之前,每个应用程序服务器(Weblogic,JBoss,Glassfish等)都有自己的JNDI命名约定,因此应用程序不能跨服务器移植。

在Java EE 6中,规范对JNDI地址进行了标准化。

来自https://docs.oracle.com/cd/E19798-01/821-1841/girgn/index.html:

Three JNDI namespaces are used for portable JNDI lookups: java:global,
java:module, and java:app.

The java:global JNDI namespace is the portable way of finding remote
enterprise beans using JNDI lookups. JNDI addresses are of the
following form:

java:global[/application name]/module name/enterprise bean
name[/interface name] Application name and module name default to the
name of the application and module minus the file extension.
Application names are required only if the application is packaged
within an EAR. The interface name is required only if the enterprise
bean implements more than one business interface.

The java:module namespace is used to look up local enterprise beans
within the same module. JNDI addresses using the java:module namespace
are of the following form:

java:module/enterprise bean name/[interface name] The interface name
is required only if the enterprise bean implements more than one
business interface.

The java:app namespace is used to look up local enterprise beans
packaged within the same application. That is, the enterprise bean is
packaged within an EAR file containing multiple Java EE modules. JNDI
addresses using the java:app namespace are of the following form:

java:app[/module name]/enterprise bean name[/interface name] The
module name is optional. The interface name is required only if the
enterprise bean implements more than one business interface.

For example, if an enterprise bean, MyBean, is packaged within the web
application archive myApp.war, the module name is myApp. The portable
JNDI name is java:module/MyBean An equivalent JNDI name using the
java:global namespace is java:global/myApp/MyBean.