关于EJB的初级问题

tlsheny 2003-10-20 09:43:03
我是个J2EE的初学者,我从资料上知道如何在客户端用LOOKUP调用EJB的HOME接口,但是我不知道如何在EJB容器内部用一个组件调用另一个组件的方法,这个问题很初级,可是我就是不会,能不能给出说明,并给个大致的代码。
...全文
35 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tlsheny 2003-10-21
  • 打赏
  • 举报
回复
老兄,您用的是哪本参考资料,能不能送给我一份
sheny@x263.net,tlsheny@sina.com.cn
不胜感激啊
naxin 2003-10-21
  • 打赏
  • 举报
回复
http://www.theserverside.com/books/masteringEJB/downloadbook.jsp

http://www.theserverside.com/books/masteringEJB/download/Mastering_EJB2.pdf
naxin 2003-10-20
  • 打赏
  • 举报
回复
For your bean to call another bean, you must go through the same process that
any other client would go through. Your bean might:
1. Look up the other bean’s home object via JNDI
2. Call create() on the home object
3. Call business methods on the EJB object
4. Call remove() on the EJB object
As we learned about earlier, to lookup a home via JNDI, you first need to supply
JNDI initialization parameters, such as the JNDI driver you’re using, which
differs from container to container. But if you’re writing a bean that calls
another bean, how do you know what JNDI service provider to use? After all,
your beans should be container-independent. Hard-coding that JNDI information
into your bean would destroy portability.
The good news is that if you’re looking up a bean from another bean, you
don’t need to supply any JNDI initialization parameters. You simply acquire a
default JNDI initial context. The container sets the default JNDI initial context
before your bean ever runs. For example, the following code snippet is taken
from a bean calling another bean:
// Obtain the DEFAULT JNDI initial context by calling the
// no-argument constructor
Context ctx = new InitialContext();
// Look up the home interface
Object result = ctx.lookup("java:comp/env/ejb/CatalogHome");
// Convert the result to the proper type, RMI-IIOP style
CatalogHome home = (CatalogHome)
javax.rmi.PortableRemoteObject.narrow(
result, CatalogHome.class);
// Create a bean
Catalog c = home.create(...);

The preceding code is portable because nobody ever needs to supply
container-specific JNDI initialization parameters.

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧