EJB 3.0 中的远程调用
我是 EJB 3.0 的新手,正在使用我的 ejb 尝试 DI。
我使用 WAS 7.0 作为我的应用程序服务器,并且在其上部署了两个 EAR。两者都有 ejb 3 会话 bean,我需要从ear 1 中可用的ejb 调用ear 2 中的ejb。
在我的两个应用程序中,我都有一个客户端项目,它保存本地和远程接口,一个commons 包含由远程和本地接口扩展的接口的项目,然后是 ejb 项目和路由器项目(作为 ejb 的 Web 服务端点)
现在为了进行远程调用,我尝试将客户端和公共 jar 文件放入EAR 的 lib 目录,更新了 ejb 项目的 META-INF 并尝试使用 @EJB 注释,但它给出了例外,即 EJB 丢失了。
我尝试进行 JNDI 查找,但它给出了 NamingException。
在 ejb 3.0 中执行远程 bean 调用的正确方法是什么?
请提供您的建议。
I'm new to EJB 3.0 and trying out the DI with my ejb's.
I'm using WAS 7.0 as my appserver and I have two EAR's deployed on it. Both have ejb 3 session beans and I need to invoke an ejb in ear 2 from an ejb available in ear 1.
In both my applications, I have a client project which holds the local and remote interfaces, a commons project which contains interfaces which are extended by the remote and local interfaces, then the ejb project and a router project(as the webservice endpoints for the ejb's)
Now to make the remote call, I tried putting the client and commons jar files in the lib directory of EAR, updated the META-INF of the ejb project and tried to use the @EJB annotation, but its giving exceptions, that the EJB's are missing.
I tried to do a JNDI lookup, but it gave NamingException.
Which is the correct way to do a remote bean invoke in ejb 3.0?
Please provide your suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于调用,问题在于首先获取对 EJB 存根的引用。对于远程 EJB,这绝对需要 JNDI 查找(除非您想通过 SOAP 或 REST 调用它)。因此,您需要将
lookup
参数添加到@EJB
注释中,并且需要向其传递正确的 JNDI 查找名称 - 这是最困难的部分,因为组合JNDI 名称很复杂并且受到很多因素的影响。The problem is not the invocation, the problem is getting a reference to the EJB's stub in the first place. For a remote EJB, this absolutely requires a JNDI lookup (unless you want to call it via SOAP or REST). Thus, you need to add the
lookup
parameter to the@EJB
annotation, and you need to pass it the correct JNDI lookup name - and that is the difficult part since the composition of JNDI names is complex and influenced by a lot of factors.