CDI:bean-discovery-mode=annotated 被忽略

CDI: bean-discovery-mode=annotated is ignored

我使用 weld 作为 CDI 容器。此外,我使用 osgi (felix)。于是就是javase+felix+weld+pax。我有以下 beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"
       bean-discovery-mode="annotated">
</beans>

我有两个 classes:

@ApplicationScoped
public class A {
  @Inject
  private B b;
  public void postCreate(@Observes ContainerInitialized event, BundleContext ctx) {
   b.test();
  }
}

和classB

public class B{
  public void test(){
  System.out.println("test is here");
  }
}

如您所见class B 没有任何@scopes 或@dependent 注释。但是,当我启动 class 的应用程序对象时,B 被注入对象 A 并调用方法测试。为什么?据我了解,它不能被注入。

编辑 1
我尝试使用 1.1 版本:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       bean-discovery-mode="annotated" version="1.1">
</beans>

但没有帮助。

您必须在 beans.xml 中指定 1.1 版本。

version="1.1" bean-discovery-mode="annotated"

现在您的 bean 部署存档是焊接的显式存档。
查看详情:enter link description here

我在焊接邮件列表中写了这篇文章,这是 Jozef Hartinger(主要焊接开发人员之一)写的

It seems that Pax CDI only implements explicit bean archives so far. I filed an issue at https://ops4j1.jira.com/browse/PAXCDI-186 You'll need to mark classes/packages you do not want discovered with @Vetoed or use an exclude filter http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#exclude_filters