Glassfish 2.1 EJB 3.0将本地EJB暴露给在同一域/ jvm中运行的其他应用程序 [英] Glassfish 2.1 EJB 3.0 Exposing local EJB to other applications running in the same domain/jvm

查看:84
本文介绍了Glassfish 2.1 EJB 3.0将本地EJB暴露给在同一域/ jvm中运行的其他应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要配置其他项目的现有项目。这需要在没有重大代码更改的情况下发生。我实际上希望只能通过配置以某种方式做到这一点。在过去的2至3天内,我阅读了有关此问题的所有资料。我了解玻璃鱼类加载器,以及对我有用的东西。

I have an existing project that I am in need of configuring different. This needs to happen without major code changes. I am actually hoping I could somehow do this only with configuration. I have spent the past 2 to 3 days reading everything I can find on this issue. I understand the glassfish classloaders, and what is available to me.

我有一个当前的示例项目,该项目的EJB定义了@Local接口。
ejb作为ejb模块部署在glassfish域中的ejb模块内部。
现在,我试图为另一个部署到同一域的应用程序找到一种方法,使其能够通过其本地接口访问该EJB。

I have a current sample project that has an EJB which defines a @Local interface. The ejb is deployed inside an ejb-module as an ejb-module into the glassfish domain. Now I am trying to find a way for another application which was deployed as an ear into the same domain, to be able to access that EJB via it's local interface.

我已阅读文档,说这是不可能的。
然后我在StackOverflow上看到了这里的帖子,网上的其他人都说有可能。但是,我找不到实际的解决方案。

I have read documentation that says this is not possible. Then I have seen posts on here at StackOverflow, and other's on the web saying it is possible. But, I cannot find the actual solution.

通过调查,我发现@Local EJB不会将自身注册到jndi(至少根据日志记录),如果我使用glassfish JNDI浏览器,我也看不到它。因此,对我来说,这是不可能的,或者EJB项目的部署有错误,并且我需要以某种方式公开它。

With investigation, I have realised that the @Local EJB does not register itself onto jndi (atleast according to the logs), if I use the glassfish JNDI browser, I also do not see it visible. So it makes sense to me, that either it's not possible, or the deployment of the EJB project is at fault, and somehow I need to expose it.

@Remote是一种可能(如果可以通过引用),并且没有性能开销。但是,允许@Local EJB访问的首选方法实际上是最终需求。

@Remote is a possibility, if it can be by reference, and no performance overhead. But the preferred method allowing @Local EJB access is really the ultimate need.

有人知道我将@Local EJB公开给另一个应用程序需要做什么吗?
还是这显然不可能?

Does anyone know what I would need to do to expose the @Local EJB to another application? Or is this plainly not possible?

我正在使用带有EJB 3.0的Glassfish 2.1

I am using Glassfish 2.1 With EJB 3.0

如果Glassfish 2.1可以处理EJB 3.1,如果它提供了此功能,我愿意转向它,但是我怀疑它是否那么简单。

If Glassfish 2.1 can handle EJB 3.1 I would be willing to move to it if it provided this capability, but I doubt it's that easy.

请协助。
谢谢。

Please assist. Thank you.

我要添加赏金。为了完成赏金计划,需要在同一域中运行2个ear应用程序,其中A.ear包含一个@Local EJB,B.ear中的应用程序也使用该EJB。

I am adding a bounty. To complete the bounty, it would be required to run 2 ear applications in the same domain, where A.ear contains an @Local EJB that is used as well by the application in a B.ear.

推荐答案

@Peter给您的链接几乎可以解决您的问题。 (链接

The link @Peter gave you almost solves your problem. (link)

要解决@Xavier的问题,需要完成的一个技巧是在相同版本(由相同的类加载器加载)中向两只耳朵提供common.jar。如果这样做,将不会引发类强制转换异常,并且可以在本地接口上使用ejb。

One trick which needs to be done to solve @Xavier's problem is to provide common.jar to both ears in the same version (loaded by the same class loader). If you do it, the class cast exception will not be thrown and you will be able to use the ejb with local interface.

要执行此操作,您需要将其设置为common。将jar放入glassfish / domains / domain1 / lib文件夹(用您的域名替换domain1)。这样,这个jar将由Glassfish的共享类加载器加载。

To do it you need to put common.jar into glassfish/domains/domain1/lib folder (substitute domain1 with you domain name). This way this jar will be loaded by a Glassfish's shared class loader.

我对具有以下结构的Eclipse和Glassfish 3进行了快速测试:

I made a quick test with Eclipse and Glassfish 3 with following structure:

package com.example;

JarShared
 - @Local class Server

EarServer
 - EjbServer
    - @Stateless class ServerBean implements Server

EarClient
 - EjbClient
    - @Stateless @LocalBean class ClientBean

查找来自ClientBean:

Lookup from ClientBean:

InitialContext ic = new InitialContext();
Server server = (Server) ic.
    lookup("java:global/EarServer/EjbServer/ServerBean!com.example.Server");

我没有收到ClassCastException,可以从ServerBean调用示例方法。

I did not get ClassCastException and I could call sample method from ServerBean.

重要说明:


  • EarServer和EarClient都不应在lib文件夹中包含JarShared,它们应该重用一个该文件夹位于域lib文件夹中。

  • 在将JarShared添加到其中之后,请记住重新启动Glassfish。

  • 要使两个ejb项目都进行编译,必须将JarShared添加到其构建路径,但仅此而已

如果您有任何疑问,请发表评论。

If you have questions, post a comment.

这篇关于Glassfish 2.1 EJB 3.0将本地EJB暴露给在同一域/ jvm中运行的其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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