从另一个 Glassfish(Web-Container)访问另一个 Glassfish(EJB-Container)中运行的远程 EJB

发布于 2024-09-17 18:18:10 字数 214 浏览 3 评论 0原文

我想使用两台独立的服务器,一台用于 Web 容器,一台用于 ejb 容器。 这两个容器都是 Glassfish V3。

但是,如何在我的 Web 项目中使用 @EJB 注释来访问远程 ejb-container 的 ejb。

在 Ejb 2.0 中,我们必须使用 ejb-descriptors,但是 Ejb3.0 和 glassfish v3 中发生了什么?

谢谢

I want to use two separate servers, one for web-container and one for ejb-container.
The both of these two containers are Glassfish V3.

But, How to use @EJB annotation in my web project to access to remote ejb-container's ejb(s).

In Ejb 2.0 we have to use ejb-descriptors but what happened in Ejb3.0 and glassfish v3?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-09-24 18:18:10

我个人从未这样做过,因为我更喜欢在同一个 JVM 中使用本地接口,因为它可以显着提高性能。

但您可以查看一下:

https://glassfish.dev.java。 net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

但您可以尝试一下:

    Properties props = new Properties();

  props.setProperty("java.naming.factory.initial",
                    "com.sun.enterprise.naming.SerialInitContextFactory");

  props.setProperty("java.naming.factory.url.pkgs",
                    "com.sun.enterprise.naming");

  props.setProperty("java.naming.factory.state",
                    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");


  // optional.  Defaults to localhost.  Only needed if web server is running
  // on a different host than the appserver   
  props.setProperty("org.omg.CORBA.ORBInitialHost", "ejb_server_ip_or_host_name");

  // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
  props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

  InitialContext ic = new InitialContext(props);

步骤 2. 在查找中使用目标远程 EJB 的全局 JNDI 名称。

EJB 3.x,假设全局 JNDI 名称为“com.acme.FooRemoteBusiness”:

 FooRemoteBusiness foo = (FooRemoteBusiness) ic.lookup("com.acme.FooRemoteBusiness");

EJB 2.x,假设全局 JNDI 名称为“com.acme.FooHome”:

Object obj = ic.lookup("com.acme.FooHome");

  FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);

I've never personally done that because I prefer using local interfaces within the same JVM as it improves performance dramatically.

But you can check this out:

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

But you can give this a try:

    Properties props = new Properties();

  props.setProperty("java.naming.factory.initial",
                    "com.sun.enterprise.naming.SerialInitContextFactory");

  props.setProperty("java.naming.factory.url.pkgs",
                    "com.sun.enterprise.naming");

  props.setProperty("java.naming.factory.state",
                    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");


  // optional.  Defaults to localhost.  Only needed if web server is running
  // on a different host than the appserver   
  props.setProperty("org.omg.CORBA.ORBInitialHost", "ejb_server_ip_or_host_name");

  // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
  props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

  InitialContext ic = new InitialContext(props);

Step 2. Use the global JNDI name of the target Remote EJB in the lookup.

EJB 3.x, assuming a global JNDI name of "com.acme.FooRemoteBusiness" :

 FooRemoteBusiness foo = (FooRemoteBusiness) ic.lookup("com.acme.FooRemoteBusiness");

EJB 2.x, assuming a global JNDI name of "com.acme.FooHome" :

Object obj = ic.lookup("com.acme.FooHome");

  FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文