应将bean.xml放在何处? [英] Where should beans.xml be placed?

查看:219
本文介绍了应将bean.xml放在何处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从7.0升级到了NetBeans 7.1.在打开JSF托管bean时,它有帮助地"告诉我找不到bean.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

解决方案

在您的情况下,可以将bean.xml放在WEB-INF目录中,因为大多数情况下bean都在WEB-INF类中.

beans.xml的正确位置取决于归档文件的类型和Bean类的位置.

在规范中对此进行了如下解释:

已启用的Bean的Bean类必须部署在Bean档案中.

  • 如果一个库jar,EJB jar,应用程序客户端jar或rar归档文件在META-INF目录中有一个名为beans.xml的文件,则它是一个Bean归档文件.
  • 如果战争的WEB-INF目录中有一个名为beans.xml的文件,那么战争的WEB-INF/classes目录就是一个bean档案.
  • 如果JVM类路径中的目录在META-INF目录中有一个名为beans.xml的文件,则它是bean档案.

I've just upgraded to NetBeans 7.1 from 7.0. On opening a JSF managed bean it "helpfully" told me that it couldn't find my beans.xml file so would I like it created for me. I knew I had a beans.xml file under WEB-INF but I said yes anyway to see what happened. A new beans.xml was created under META-INF for me.

Thinking I'd made a mistake I deleted the file under WEB-INF only to have my application fail at start up. Putting beans.xml back into WEB-INF fixed that problem. This page seems to think both locations are valid: http://seamframework.org/Documentation/WhatIsBeansxmlAndWhyDoINeedIt

So, the question is which folder should beans.xml live in WEB-INF or META-INF?

I'm running GlassFish 3.1.1 and Java 7

解决方案

Having beans.xml placed to the WEB-INF directory is fine in your case, because most likely beans are under WEB-INF classes.

Correct place for beans.xml depends about type of archive and location of bean classes.

In specification this is explained as follows:

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.

这篇关于应将bean.xml放在何处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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