gpt4 book ai didi

java-ee-6 - beans.xml 应该放在哪里?

转载 作者:行者123 更新时间:2023-12-03 10:38:27 25 4
gpt4 key购买 nike

我刚刚从 7.0 升级到 NetBeans 7.1。在打开 JSF 托管 bean 时,它“很有帮助”地告诉我它找不到我的 beans.xml 文件,所以我希望它为我创建。我知道我在 WEB-INF 下有一个 beans.xml 文件,但我还是答应了,看看发生了什么。在 META-INF 下为我创建了一个新的 beans.xml。

我以为我犯了一个错误,我删除了 WEB-INF 下的文件,结果我的应用程序在启动时失败。将 beans.xml 放回 WEB-INF 解决了该问题。此页面似乎认为两个位置都有效:http://seamframework.org/Documentation/WhatIsBeansxmlAndWhyDoINeedIt

那么,问题是 beans.xml 应该放在 WEB-INF 还是 META-INF 中的哪个文件夹中?

我正在运行 GlassFish 3.1.1 和 Java 7

最佳答案

将 beans.xml 放入 WEB-INF 目录在您的情况下很好,因为最有可能的 bean 位于 WEB-INF 类下。

beans.xml 的正确位置取决于归档类型和 bean 类的位置。

在规范中,这解释如下:

Bean classes of enabled beans must be deployed in bean archives.

  • A library jar, EJB jar, application client jar or rar archive is a bean archive if it has a file named beans.xml in the META-INF directory.
  • The WEB-INF/classes directory of a war is a bean archive if there is a file named beans.xml in the WEB-INF directory of the war.
  • A directory in the JVM classpath is a bean archive if it has a file named beans.xml in the META-INF directory.

关于java-ee-6 - beans.xml 应该放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8991561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com