使用 glassfish 为多个 Web 项目共享 ejb 3

发布于 2024-09-29 22:05:46 字数 466 浏览 0 评论 0原文

我目前有一个包含 EJB 和 WAR 的 J2EE 项目。一切都很顺利,而我在最终的 EAR 中只捆绑了一个 WAR 和一个 EJB 模块。我现在需要使用相同的 EJB 模块开发另一个 WAR。

所以,我在新的WAR的库中添加了EJB模块。问题是,当我尝试部署与两个 WAR 和共享 EJB 捆绑在一起的 EAR 时,出现以下异常:

Caused by: java.lang.RuntimeException: Error while binding JNDI name com.alex.ejb.MyBeanRemote__3_x_Internal_RemoteBusinessHome__ for EJB : MyBean

当我从第二个 WAR 的库中删除 EJB 时,一切又恢复正常了。

有什么我错过的吗?

最后,真正的问题是“如何在多个 Web 应用程序中共享 EJB?”

感谢您的帮助

I currently have a J2EE project containing an EJB and a WAR. Everything goes fine while I have only one WAR and one EJB module bundled in the final EAR. I now need to develop an other WAR using the same EJB module.

So, I added the EJB module in the library of the new WAR. The problem is when I try to deploy the EAR bundled with the two WAR and the shared EJB, I get the following exception :

Caused by: java.lang.RuntimeException: Error while binding JNDI name com.alex.ejb.MyBeanRemote__3_x_Internal_RemoteBusinessHome__ for EJB : MyBean

As I remove the EJB from the library of the second WAR, everything work again.

Is there something I missed ?

Finally, the real question is "how to share an EJB within multiple web applications ?"

Thanks for help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双手揣兜 2024-10-06 22:05:46

问题是当我尝试部署与两个 WAR 和共享 EJB 捆绑在一起的 EAR 时,出现以下异常 (...)

这是因为 bean 部署了两次,导致命名冲突。实际上,在使用 EAR 打包时,这不是您应该打包应用程序的方式。

最后,真正的问题是“如何在多个 Web 应用程序中共享 EJB?”

不要将 EJB 模块放在 Web 模块的 WEB-INF/lib 文件夹中,您的 EAR 应具有以下结构:

myear.ear
|-- META-INF
|   |-- application.xml
|   `-- sun-application.xml (optional)
|-- myejbmodule1-ejb.jar
|-- ...
|-- myejbmoduleN-ejb.jar
|-- mywebapp1-war.war
`-- mywebapp2-war.war

资源

The problem is when I try to deploy the EAR bundled with the two WAR and the shared EJB, I get the following exception (...)

That's because the beans get deployed twice, causing a naming collision. Actually, that's just not how you should package your application when using an EAR packaging.

Finally, the real question is "how to share an EJB within multiple web applications ?"

Don't put your EJB module(s) in the WEB-INF/lib folder of your Web modules, your EAR should have the following structure:

myear.ear
|-- META-INF
|   |-- application.xml
|   `-- sun-application.xml (optional)
|-- myejbmodule1-ejb.jar
|-- ...
|-- myejbmoduleN-ejb.jar
|-- mywebapp1-war.war
`-- mywebapp2-war.war

Resources

后知后觉 2024-10-06 22:05:46

您不需要在新的 WAR 中包含 EJB,您可以简单地使用 JNDI 或通过注入来查找它。在针对它进行编译方面,您可以创建一个 JAR,其中仅包含您需要使用的接口以及新项目的类路径。

You do not need to include the EJB in the new WAR, you can simply look it up using JNDI or by injecting it. In terms of compiling against it, you can create a JAR that simply contains the interface(s) you need to use, and that to the classpath of your new project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文