【发布时间】:2018-10-10 12:35:48
【问题描述】:
我目前正在为 Java SE(焊接)测试 CDI 2.0 - 我读到,没有必要使用 beans.xml,所以我尝试了这个:
你好.class:
public class Hallo {
public String sayHallo() {
return "hallo";
}
}
然后我有一个Test.class:
@ApplicationScoped
public class Test {
@Inject Hallo hallo;
public String sayHallo() {
return hallo.sayHallo() + " from Test";
}
}
最后我在这里尝试使用 CDI:
public class Demo {
public static void main(String[] args) {
SeContainerInitializer initializer = SeContainerInitializer.newInstance();
/** disable discovery and register classes manually */
try (SeContainer container = initializer.disableDiscovery().addPackages(Demo.class).initialize()) {
Test test = container.select(Test.class).get();
test.sayHallo();
}
}
}
不幸的是,它不起作用。我收到这条消息:
2018 年 10 月 10 日下午 2:22:04 org.jboss.weld.bootstrap.WeldStartup 信息:WELD-000900:3.0.5(最终)
2018 年 10 月 10 日下午 2:22:05 org.jboss.weld.bootstrap.WeldStartup startContainer 信息:WELD-000101:交易服务不可用。 @Inject UserTransaction 的注入不可用。事务性观察者将被同步调用。
2018 年 10 月 10 日下午 2:22:05 org.jboss.weld.environment.se.WeldContainer fireContainerInitializedEvent 信息:WELD-ENV-002003:焊接 SE 容器 5adc2948-acd7-423c-84dc-c1463534c309 已初始化
2018 年 10 月 10 日下午 2:22:05 org.jboss.weld.environment.se.WeldContainer 关闭 信息:WELD-ENV-002001:焊接 SE 容器 5adc2948-acd7-423c-84dc-c1463534c309 关闭
我错过了什么?
提前致谢。
【问题讨论】:
标签: java dependency-injection weld