CDI:beans.xml,我在哪里放你? [英] CDI: beans.xml, where do I put you?
问题描述
我使用Weld作为CDI实现。当我在 src / test / java / META-INF / beans.xml中有空beans.xml时,我的集成测试试图组装对象图,实例化Weld容器效果很好
。这是一个简单的测试:
I am using Weld as CDI implementation. My integration test, that tries to assemble object graph instantiating Weld container works well, when I have empty beans.xml in src/test/java/META-INF/beans.xml
. Here is that simple test:
public class WeldIntegrationTest {
@Test
public void testInjector() {
new Weld().initialize();
// shouldn't throw exception
}
}
现在当我运行 mvn clean install
时,我总是得到: META-INF中缺少beans.xml文件!
Now when I run mvn clean install
, I always get: Missing beans.xml file in META-INF!
我的根文件夹是src和web,其中包含WEB-INF文件夹,但我也尝试使用默认的maven结构并将web重命名为webapp,把它移到了src / main。我尝试了所有合理的位置:
My root folders are "src" and "web" which contains WEB-INF folder, but I also tried to use default maven structure and renamed "web" to "webapp" and moved it to src/main. I tried all the reasonable locations I could thought of:
- src/main/java/META-INF/beans.xml
- src/test/java/META-INF/beans.xml
- web/WEB-INF/beans.xml
- src/main/webapp/WEB-INF/beans.xml
- src/main/webapp/META-INF/beans.xml
- src/main/webapp/META-INF/(empty) and src/main/webapp/WEB-INF/beans.xml
到目前为止没有任何作用:/
Nothing works so far :/
推荐答案
对于EJB和JAR打包,您应该将 beans.xml
放在 src / main / resources / META-INF中/
。
For EJB and JAR packaging you should place the beans.xml
in src/main/resources/META-INF/
.
对于WAR打包,您应该将 beans.xml
放在 src / main / webapp / WEB-INF /
。
For WAR packaging you should place the beans.xml
in src/main/webapp/WEB-INF/
.
请记住只有 .java
文件应放在 src / main / java
和 src / test / java
目录中。像 .xml
这样的资源应该在 src / main / resources
中。
Remember that only .java
files should be put in the src/main/java
and src/test/java
directories. Resources like .xml
files should be in src/main/resources
.
这篇关于CDI:beans.xml,我在哪里放你?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!