如何在单独的Web应用程序中访问EJB实现远程接口? [英] How do i access EJB implementing remote interface in separate web application?

查看:146
本文介绍了如何在单独的Web应用程序中访问EJB实现远程接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans 6.8和Glassfish v3.0。

I am using Netbeans 6.8 and Glassfish v3.0.

我创建了一个ejb模块并从数据库创建了实体类,然后创建了带有远程接口的无状态会话bean。比如说。

I created an ejb module and created entity classes from database and then created stateless session bean with remote interface. Say eg.

 @Remote
public interface customerRemote{
    public void add(String name, String address);
    public Customer find(Integer id);
}

@Stateless
public class customerBean implements customerRemote{
    //implementations of methods
}

然后我创建了一个新的Web应用程序。但是现在我如何在我的Web应用程序中访问远程ejb。我可以用jndi名称查找一个bean,但我想知道的是,它将返回什么类型的对象?我如何在customerRemote中进行类型转换?我的Web应用程序中没有任何名为customerRemote的类。那么,我该怎么做?另外,实体类客户怎么样?我的Web应用程序中也没有名为Customer的类。所有ejb和实体类都在单独的ejb模块中。请帮助我:(

Then i created a new web application. But now how do i access remote ejb's in my web application. I could lookup a bean with jndi name but what i want to know is, what type of object it will return? How do i typecast it in customerRemote? I don't have any class named customerRemote in my web application. So, how do i do it? Also, what about the entity class Customer? There is no such class named Customer in my web application also. All ejb's and entity classes are in separate ejb module. Please help me :(

推荐答案


如何在
customerRemote中对其进行类型转换?I在我的web
应用程序中没有任何名为customerRemote的类
。那么,我该怎么做呢?另外,
实体类客户怎么样?
没有这样的我的Web应用程序中也有一个名为Customer
的类。所有ejb的
和实体类都在单独的ejb
模块中。

How do i typecast it in customerRemote? I don't have any class named customerRemote in my web application. So, how do i do it? Also, what about the entity class Customer? There is no such class named Customer in my web application also. All ejb's and entity classes are in separate ejb module.

您的Web应用程序必须依赖于包含这些类和接口的库。然后您将能够像往常一样导入接口和类型转换。您有两种方法:

Your web application must depend on a library that contains these classes and interfaces. Then you will be able to import the interface and typecast as usual. You have two approaches:


  • 所有在一个jar 。这似乎就是你现在所拥有的。在这种情况下,你的网络应用程序需要依赖这个jar。

  • All in one jar. This seems to be what you have now. In this case your web app needs to depend on this jar.

拆分API和实现。更好的方法是将ejb模块拆分为两个罐子:一个罐子 myModule -api 包含该类属于您的模块的API的es。在这种情况下, customerRemote Customer 。另一个jar myModule-impl 包含实现(当然,实现依赖于API)。然后在您的Web应用程序中,您只需要依赖于 myModule-api 中的API。

Split API and implementation. A better approach is to split your ejb module in two jars: one jar myModule-api contains the classes that belong to the API of your module. In this case that would be customerRemote and Customer. And another jar myModule-impl contains the implementation (the implementation depends on the API of course). Then in your web app, you only need to depend on the API which is in myModule-api.

这篇关于如何在单独的Web应用程序中访问EJB实现远程接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆