如何从远程客户端访问实体bean?
我在服务器中有这个:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在客户端包含包含接口、实体和实体的 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