我在服务器中有这个:
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是一个类?
我是否必须在我的客户端(以及HelloServiceRemote类)中重新编写Person类,因此它可以理解什么是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 ?
最满意答案
您必须在客户端包含jar项目,包含使用的接口,实体和其他实用程序类。
但是在客户端暴露实体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
更多推荐
发布评论