如何从远程客户端访问实体bean?

发布于 2024-09-25 18:55:42 字数 800 浏览 0 评论 0原文

我在服务器中有这个:

class Person{...}

并且

@Stateless
public class HelloServiceBean implements HelloServiceLocal, HelloServiceRemote {
    public Person getPerson(String name) {
        return new Person(name);
    }
}

我在我的客户端(在某些不同的 JVM 中)中有这个:

  public static void main(String[] a) throws Exception{
        String name = "java2s";
        HelloServiceRemote service = null;

        service = (HelloServiceRemote)new InitialContext().lookup("HelloServiceBean/remote");
        Person p = service.getPerson(name));
   }

例如,当我需要从我的 EJB 调用 getPerson() 方法(该方法返回 Person 类型的对象)时,我如何客户会明白 Person 是一个类吗?

我是否必须在客户端中重新编写 Person 类(以及 HelloServiceRemote 类),以便它可以理解什么是 Person ?或者我是否必须将 Ejb 项目包含到我的客户端项目中?

i have this in the server:

class Person{...}

and

@Stateless
public class HelloServiceBean implements HelloServiceLocal, HelloServiceRemote {
    public Person getPerson(String name) {
        return new Person(name);
    }
}

And i have this in my client (in some different JVM):

  public static void main(String[] a) throws Exception{
        String name = "java2s";
        HelloServiceRemote service = null;

        service = (HelloServiceRemote)new InitialContext().lookup("HelloServiceBean/remote");
        Person p = service.getPerson(name));
   }

When i need to call, for example, getPerson() method from my EJB, which return an object of type of Person, how my client is going to understand that Person is a class ?

Do i have to re-write the Person class another time in my client (and also the HelloServiceRemote class), so it can understand what is a Person ? Or do i have to include the Ejb project into my client project ?

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

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

发布评论

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

评论(1

凉栀 2024-10-02 18:55:43

您必须在客户端包含包含接口、实体和实体的 EJB 项目的 jar。使用的其他实用程序类。

但在客户端公开 Entity Bean 并不可取,您可以在 http://www.ibm.com/developerworks/websphere/library/bestpractices/ejbs_access_entity_bean.html

You have to include jar of EJB project at client side containing Interfaces, Entities & other utility classes used.

But exposing Entity Beans at client side is not preferable, you can get more information regarding this at http://www.ibm.com/developerworks/websphere/library/bestpractices/ejbs_access_entity_bean.html

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