[英]CDI WELD Beans.xml in META-INF from jar in lib blocking the one in WEB-INF of project
Depending on where I place my beans.xml's, in my project CDI is either working for @Named annotated classes found in lib jars OR for @Alternative annotated classes found in the main project. 根据在我的项目中放置bean.xml的位置的不同,CDI可以用于在lib jar中找到的@Named注释类,也可以用于在主项目中找到的@Alternative注释类。 I can't figure out where to place them to get both to work.
我不知道在哪里放置它们才能使它们都正常工作。
Upon building I have a core.jar that has some @Default annotated classes and some @Named annotated classes. 构建后,我有一个core.jar,其中包含一些@Default注释类和一些@Named注释类。
The core.jar is located in the web-inf/lib in my project. core.jar位于我的项目中的web-inf / lib中。
In that project, depending on environment build, I use some @Alternative annotated classes which are specified in the beans.xml of the web project (in WEB-INF) 在该项目中,根据环境的构建,我使用一些@Alternative注释的类,这些类在Web项目的bean.xml中指定(在WEB-INF中)
So, I have 2 beans.xml 所以,我有2 beans.xml
1 in the META-INF of a core.jar that is build and placed in the project lib AND 1 in the WEB-INF of the war project that gets deployed (with alternatives specified) 在core.jar的META-INF中为1,该core.jar已构建并放置在项目lib中,而在部署的war项目的WEB-INF中为1(指定了替代方案)
With both beans.xml files at those locations, the beanhandler does not find the alternatives specified in the beans.xml (the one in the web-inf of the war) 在两个bean.xml文件都位于这些位置的情况下,beanhandler找不到在bean.xml中指定的替代项(战争的web-inf中的那个)
When I remove the beans.xml from the META-INF from the jar dependency and redeploy, the alternatives are working fine (strangely) but then the @Named annotated classes are no longer found... 当我从jar依赖项中从META-INF中删除bean.xml并重新部署时,替代方法工作正常(奇怪),但是随后不再找到@Named注释类...
Any ideas? 有任何想法吗?
Could you try: 您可以尝试:
From CDI 1.1 onwards the alternative can be enabled for the whole
application using @Priority annotation.
As described in alternatives then you would not need to depend on beans.xml as activation point for the alternatives. 如替代方案中所述,那么您无需依赖beans.xml作为替代方案的激活点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.