EAR 与单独的 EJB + WAR [英] EAR vs separate EJB + WAR

查看:22
本文介绍了EAR 与单独的 EJB + WAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将应用程序部署为 EAR(带有 1 个 EJB 和 1 个 WAR 模块)与单独的模块有什么区别?我想使用 GlassFish 3 Web 配置文件,但它不支持 EAR 存档.我可以简单地将 EJB 和 WAR 用作单独的模块吗?还有其他选择吗?

What's the difference in deploying application as EAR (with 1 EJB and 1 WAR module) vs separate modules? I want to use GlassFish 3 web profile but it does not support EAR archive. Can I simply use EJB and WAR as separate modules? Any other options?

推荐答案

3 种部署变体之间似乎有些混淆:

There seems to be some confusion between 3 variants of deployment:

  1. 包含 EJB 和 WEB 模块的 EAR
  2. 部署单独的 EJB 模块和单独的 WEB 模块
  3. 部署包含 EJB 类或 EJB jar 的 WEB 模块.

在第一种情况下,您在逻辑上有一个应用程序,但一个应用程序分为两层.WEB 模块与EJB 模块隔离,它可以消费来自EJB 模块的类,但EJB 模块不能消费来自WEB 模块的类.由于它是对 EJB bean 的单个应用程序本地访问,因此可以使用 EJB bean 的注入按预期工作.

In the first situation, you have logically one application, but one that is divided in two tiers. The WEB module is isolated from the EJB module in the sense that it can consume classes from EJB module, but the EJB module can not consume classes from the WEB module. Since it's a single application local access to EJB beans can be used and injection of EJB beans works as expected.

在第二种情况下(您似乎在问题中提到了这种情况),没有逻辑上的单个应用程序,而是两个独立的模块.它们确实在同一个 JVM 中运行,但官方 Java EE 不允许使用本地访问,必须使用远程访问(尽管实际上本地访问通常仍然有效).此外,在 Web 模块的 bean 中注入 EJB bean 不能直接使用简单的 @EJB 注释,而是必须使用 lookup 属性来指定全局JNDI 名称.

In the second situation (which you seem to be referring to in your question) there isn't a logical single application, but really two separate modules. They do run in the same JVM, but officially Java EE does not allow to use local access and remote access has to be used (although practically local access often works anyway). Also, injection of EJB beans in beans in the web module does not work directly with a simple @EJB annotation, but instead the lookup attribute has to be used that specifies the global JNDI name.

最后,第三种情况(您似乎没有提到,但家"提到了)与第一种情况有点相似,但在这种情况下没有层级和隔离.EJB bean 可以直接从 Web 模块的其余部分访问所有类.

Finally, the third situation (which you don't seem to mention, but 'home' mentions) is a bit similar to the first one, but there are no tiers and isolation in this case. EJB beans can access all classes from the rest of the web module directly.

Web 配置文件仅支持最后一种部署情况.EAR 和独立 EJB 部署均不受支持.

The web profile only supports this last deployment situation. Both EAR and standalone EJB deployments are not supported.

这篇关于EAR 与单独的 EJB + WAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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