【发布时间】:2015-05-25 06:19:47
【问题描述】:
我使用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>
我有两个班级:
@ApplicationScoped
public class A {
@Inject
private B b;
public void postCreate(@Observes ContainerInitialized event, BundleContext ctx) {
b.test();
}
}
B类
public class B{
public void test(){
System.out.println("test is here");
}
}
如您所见,B 类没有任何@scopes 或@dependent 注释。但是,当我启动应用程序时,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>
但它没有帮助。
【问题讨论】:
-
您使用的是实现 CDI 1.0 的 1.x 版本的焊接吗?
-
@Sebastian S 我正在使用实现 CDI 1.1 的 2.2.10 版本。
标签: java osgi cdi apache-felix weld