java 仅作为 WAR 部署的 EJB 3.1 应用程序:ejb-jar.xml 怎么样?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3336727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:22:56  来源:igfitidea点击:

EJB 3.1 application deployed as WAR-only: What about ejb-jar.xml?

javajakarta-eejava-ee-6ejb-3.1

提问by Ingo Fischer

I have a JavaEE6 application, consisting of Web stuff and EJBs and which is deployed as WAR-only (using EJB3.1). The build is based on Maven. I just read about a new possibility to order the module initialization in Java EE 6 herewhich i also need for my application. Also, i would like to have an option to define some EJB properties in XML.

我有一个 JavaEE6 应用程序,由 Web 内容和 EJB 组成,并且仅作为 WAR 部署(使用 EJB3.1)。构建基于Maven。我刚刚看了一下新的可能命令在Java EE 6的初始化模块在这里,我还需要我的应用程序。此外,我希望有一个选项可以在 XML 中定义一些 EJB 属性。

Since the example is deployed as an EAR-project the order is defined in the application.xml. But in a WAR-deployed project, there is no application.xml. Now i wonder where i can define such informations? Or is it possible to use an application.xml somehow in a WAR-deployed-app?

由于示例部署为 EAR 项目,因此在 application.xml 中定义了顺序。但是在 WAR 部署的项目中,没有 application.xml。现在我想知道在哪里可以定义这些信息?或者是否可以在 WAR 部署的应用程序中以某种方式使用 application.xml?

EDIT:

编辑:

Oops i didn't read the module-order-example right, in the first moment i thought it was about in which order the EJBs in my app are loaded. Of course i have only one module in my WAR-app, so ordering makes no sense.

哎呀,我没有正确阅读模块顺序示例,一开始我以为是关于我的应用程序中的 EJB 加载顺序的问题。当然,我的 WAR 应用程序中只有一个模块,因此订购毫无意义。

Ok, but as i'm at it, one big question remains (also altered the question title to reflect the change): What about the ejb-jar.xml? Can i somehow define stuff about my EJBs in XML (as its useful for some settings, to avoid recompilation)?

好的,但就我而言,仍然存在一个大问题(还更改了问题标题以反映更改):ejb-jar.xml 怎么样?我能否以某种方式在 XML 中定义关于我的 EJB 的内容(因为它对某些设置很有用,以避免重新编译)?

回答by Vineet Reynolds

In short, it is not possible with a WAR based deployment.

简而言之,基于 WAR 的部署是不可能的。

The module initialization feature of Java EE 6 is meant for initializing different modules of an application in a specific order. The moment you have a WAR based EJB application, you no longer have separate modules for your EJB and Web application. There is just one module - the web application modulein a WAR based deployment.

Java EE 6 的模块初始化特性旨在以特定顺序初始化应用程序的不同模块。当您拥有基于 WAR 的 EJB 应用程序时,您的 EJB 和 Web 应用程序不再有单独的模块。只有一个模块 -基于 WAR 的部署中的Web 应用程序模块

Therefore, if you have to achieve the same feature as the module initialization order, offered in Java EE 6, you'll have to do either of the following:

因此,如果您必须实现与 Java EE 6 中提供的模块初始化顺序相同的功能,则必须执行以下任一操作:

  • Separate the EJB into a separate module, and use a EAR based deployment.
  • This is more or less trickery, as was done in Java EE 5, and you would want to be avoiding it. You might want to code in logic to ensure that the singleton EJBs have been created (assuming that this is due to the use of singletons in your application), before they're utilized in code.
  • 将 EJB 分成单独的模块,并使用基于 EAR 的部署。
  • 这或多或少有点诡计,就像在 Java EE 5 中所做的那样,您可能希望避免它。您可能希望在逻辑中编码以确保在代码中使用单例 EJB 之前已创建它们(假设这是由于在应用程序中使用了单例)。

Location of the ejb-jar.xml in a WAR file

ejb-jar.xml 在 WAR 文件中的位置

The EJB 3.1 specification(in the chapter on Packaging) addresses the issue of the location of the ejb-jar.xml file when deployed in a WAR:

EJB 3.1 规范(在打包一章中)解决了在 WAR 中部署时 ejb-jar.xml 文件的位置问题:

In a .war file, the deployment descriptor is stored with the name WEB-INF/ejb-jar.xml.

在 .war 文件中,部署描述符以名称 WEB-INF/ejb-jar.xml 存储。

PS: I haven't tried this style of deployment yet. YMMV.

PS:我还没有尝试过这种部署方式。天啊。

回答by David Blevins

Side note on EJBs in .wars and ejb-jar.xml processing. As already noted the location is WEB-INF/ejb-jar.xml, but also note that is the onlylocation checked even if there are ejbs jars inside WEB-INF/lib/ -- via standard rules any META-INF/ejb-jar.xml files there are ignored.

关于 .wars 和 ejb-jar.xml 处理中的 EJB 的旁注。如前所述,位置是 WEB-INF/ejb-jar.xml,但还要注意,即使 WEB-INF/lib/ 中有 ejbs jar ,它也是唯一检查的位置——通过标准规则,任何 META-INF/ejb- jar.xml 文件将被忽略。

The Expert Group was rather split on that one, so if you have a preference it's not too late to send feedback to the EJB 3.1 expert group list for consideration in EJB.next.

专家组在这个问题上存在分歧,因此如果您有偏好,现在将反馈发送到 EJB 3.1 专家组列表以供在 EJB.next 中考虑还为时不晚。

My vote was to still allow individual jars to have META-INF/ejb-jar.xml files just as these jars can now have persistence.xmls, beans.xmls, web fragments etc. The larger issue for me was that it is at odds with the Embedded EJB Container API which supports an EAR-style classpath which allows several jars/modules each possibly containing a META-INF/ejb-jar.xml file. The result being if you do use the Embedded API to test a multi-jar ejb app that is composed into a single .war file, you are then faced with the task of merging any ejb-jar.xml data you have into a single ejb-jar.xml for the webapp. Sort of a pain for users.

我的投票是仍然允许单个 jars 拥有 META-INF/ejb-jar.xml 文件,就像这些 jars 现在可以拥有 persistence.xmls、beans.xmls、web 片段等一样。对我来说更大的问题是它不一致使用嵌入式 EJB 容器 API,该 API 支持 EAR 样式的类路径,该类路径允许多个 jar/模块,每个可能包含一个 META-INF/ejb-jar.xml 文件。结果是,如果您确实使用嵌入式 API 来测试组合成单个 .war 文件的多 jar ejb 应用程序,那么您将面临将您拥有的任何 ejb-jar.xml 数据合并到单个 ejb 中的任务-jar.xml 用于 web 应用程序。对用户来说有点痛苦。