简体   繁体   English

如何指定从中获取EJB的服务器?

[英]How do I specify a server to get an EJB from?

In java EE, the way you get an EJB from a remote server is by looking it up in JNDI. 在Java EE中,从远程服务器获取EJB的方法是在JNDI中查找它。 The specification defines the JNDI name for a given bean type. 规范定义了给定bean类型的JNDI名称。

However, this seems to be only if you want to get a bean off your local computer. 但是,这似乎仅是要从本地计算机上获取Bean时才使用。 I want to get the bean off a remote server, like most users would. 我想像大多数用户一样将bean从远程服务器上删除。 How do I specify the server URL? 如何指定服务器URL? Do I pass a map to the InitialContext constructor? 是否将映射传递给InitialContext构造函数?

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. 注意: 另一个问题几乎相同,但是自从规范定义可移植JNDI名称以来,这个问题已经过时。

You do JNDI lookups of remote EJBs using exactly the same code as you would use when running server-side: 您可以使用与运行服务器端时完全相同的代码来进行远程EJB的JNDI查找:

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;

To make the naming context work, you must run your application as a Java EE application client . 要使命名上下文起作用,您必须将应用程序作为Java EE 应用程序客户端运行 An application client is exactly like a regular standalone Java program, with a standard main method; 应用程序客户端与常规的独立Java程序完全一样,具有标准的main方法; 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. Java EE Spec中没有指定这种方式,因此每个应用程序服务器都有其自己的方式。

GlassFish, for example, requires an application client to include some special jars in the classpath , and set a couple system properties . 例如,GlassFish要求应用程序客户端在类路径中包括一些特殊的jar ,并设置几个系统属性 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. 具体来说,您必须在目录路径中包含lib/gf-installer.jar及其清单所引用的所有jar,并且必须设置org.omg.CORBA.ORBInitialHostorg.omg.CORBA.ORBInitialPort系统属性。

I want to get the bean off a remote server 我想从远程服务器上获取bean

Yes, you need specify the IP/port where the remote server (JNDI service) is running/listening. 是的,您需要指定运行/监听远程服务器(JNDI服务)的IP /端口。

How do I specify the server URL? 如何指定服务器URL?

You have to set the propertie: java.naming.provider.url and make it available to the InitialConetxt. 您必须设置属性: java.naming.provider.url并将其提供给InitialConetxt使用。

This can be done in different ways : 这可以通过不同的方式完成:

  1. to use a jndi.properties file 使用jndi.properties文件
  2. to use system properties 使用系统属性
  3. passing the value in a Hashtable when you create a new instance of InitialContext object. 创建InitialContext对象的新实例时,将值传递到Hashtable中。

The concrete value of this and others necessary properties to instantiate the InitialConetct are vendor dependen. 实例化InitialConetct的此属性和其他必要属性的具体值取决于供应商。 An example for JBoss could be: JBoss的示例可能是:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://yourServer:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Keep in mind that there is no way that you can get the EJB's stub from a remote server if you don´t indicate the url. 请记住,如果不指定URL,则无法从远程服务器获取EJB存根。 By "Remote" I mean the client and the server are running in different JVM. “远程”是指客户端和服务器在不同的JVM中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Maven中的WAR项目中指定EJB引用? - How do I specify EJB reference in WAR project in Maven? 除了EAR和EJB之外,我从Java EE应用服务器获得了什么,而我没有像Tomcat那样进入servlet容器? - Besides EAR and EJB, what do I get from a Java EE app server that I don't get in a servlet container like Tomcat? 如何测试EJB是否在JBoss AS 7服务器上运行 - How do I test if EJB is running on JBoss AS 7 server 如何在ejb中设置和获取会话属性 - How do i set and get session attributes in ejb Java:如何从二维双精度数组中获取指定坐标的整数(x,y) - Java: How do I get the integer (x,y) of a specify coordinate from a 2d double array 如何在EJB中设置事务隔离? - How do i set the Transaction Isolation in EJB? 我如何从EJB3和JBoss开始? - How do I start with EJB3 and JBoss? 如何创建EJB Timer服务并将其部署到以eclipse运行的weblogic 9.2服务器? - How do I create an EJB Timer service and deploy it to a weblogic 9.2 server running in eclipse? 使用JBoss ESB,如何从烟雾中获取多个对象并将其用作ejb的参数? - Using JBoss ESB, how do I get multiple objects out of smooks and use them as params to an ejb? 如何获取服务器到客户端的更新通知? - how do I get update notification from server to client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM