CDI: beans.xml, where do I put you?

风格不统一 提交于 2019-11-27 00:36:35

For EJB and JAR packaging you should place the beans.xml in src/main/resources/META-INF/.

For WAR packaging you should place the beans.xml in src/main/webapp/WEB-INF/.

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.

Just to complement the above answer, here is an official reference on this: https://docs.oracle.com/javaee/6/tutorial/doc/gjbnz.html

quote:

An application that uses CDI must have a file named beans.xml. The file can be completely empty (it has content only in certain limited situations), but it must be present. For a web application, the beans.xml file must be in the WEB-INF directory. For EJB modules or JAR files, the beans.xml file must be in the META-INF directory.

http://www.javamonamour.org/2017/11/cdi-in-java-se-8.html here you can see where I have put it with success, that is under src/META-INF . The post contains a full working example of CDI in Java SE.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!