如何指定服务器来获取EJB? [英] How do I specify a server to get an EJB from?

查看:96
本文介绍了如何指定服务器来获取EJB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java EE中,从远程服务器获取EJB的方式是在JNDI中查找。该规范为给定的bean类型定义了JNDI名称。

In java EE, the way you get an EJB from a remote server is by looking it up in JNDI. The specification defines the JNDI name for a given bean type.

但是,这似乎只是想要从本地计算机上获取一个bean。我想把bean从一个远程服务器上删除,就像大多数用户一样。如何指定服务器URL?我将地图传递给 InitialContext 构造函数?

However, this seems to be only if you want to get a bean off your local computer. I want to get the bean off a remote server, like most users would. How do I specify the server URL? Do I pass a map to the InitialContext constructor?

注意:另外一个问题几乎是一样的,但是从规范中定义了便携式JNDI名称后,已经过时了。

Note: There is another question that is pretty much the same, but that has become out of date since the definition of portable JNDI names by the specification.

推荐答案

您可以使用与运行服务器端时使用的代码完全相同的代码执行远程EJB的JNDI查找:

You do JNDI lookups of remote EJBs using exactly the same code as you would use when running server-side:

Context context = new InitialContext();  // No properties needed
MyEJB myEjbInstance = (MyEJB) context.lookup("ejb/MyEJB");

或者,您当然可以注意:

Or, of course, you can inject it:

@EJB
private MyEJB myEjbInstance;

为了使命名上下文有效,您必须以Java EE应用程序客户机的形式运行应用程序。应用程序客户端就像一个常规的独立Java程序,标准的 main 方法;唯一的区别是它需要以不同的方式运行。在Java EE规范中没有指定这种方式,所以每个应用程序服务器都有自己的方法。

To make the naming context work, you must run your application as a Java EE application client. An application client is exactly like a regular standalone Java program, with a standard main method; the only difference is that it needs to be run in a different manner. That manner is not specified in the Java EE Spec, so each application server has its own way of doing it.

GlassFish需要一个应用程序客户端设置几个系统属性。具体来说,您必须在您的类路径中包含 lib / gf-installer.jar 及其清单引用的所有jar,并且必须设置 org。 omg.CORBA.ORBInitialHost org.omg.CORBA.ORBInitialPort 系统属性。

GlassFish, for example, requires an application client to include some special jars in the classpath, and set a couple system properties. Specifically, you must include lib/gf-installer.jar and all the jars referenced by its manifest in your classpath, and you must set the org.omg.CORBA.ORBInitialHost and org.omg.CORBA.ORBInitialPort system properties.

这篇关于如何指定服务器来获取EJB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆