Java SE 和焊接?
Java SE and Weld?
我目前正在为 Java SE(焊接)测试 CDI 2.0 - 我读到,没有必要使用 beans.xml,所以我试了一下:
Hallo.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();
}
}
}
不幸的是,它不起作用。我收到这条消息:
Okt 10, 2018 2:22:04 PM org.jboss.weld.bootstrap.WeldStartup
INFO: WELD-000900: 3.0.5 (Final)
Okt 10, 2018 2:22:05 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Okt 10, 2018 2:22:05 PM org.jboss.weld.environment.se.WeldContainer fireContainerInitializedEvent
INFO: WELD-ENV-002003: Weld SE container 5adc2948-acd7-423c-84dc-c1463534c309 initialized
Okt 10, 2018 2:22:05 PM org.jboss.weld.environment.se.WeldContainer shutdown
INFO: WELD-ENV-002001: Weld SE container 5adc2948-acd7-423c-84dc-c1463534c309 shut down
我错过了什么?
提前致谢。
CDI 容器工作正常。
Transactional services not available
声明您不在事务管理器下 运行,默认情况下,您(几乎)在应用程序服务器中 运行 拥有事务管理器。
我目前正在为 Java SE(焊接)测试 CDI 2.0 - 我读到,没有必要使用 beans.xml,所以我试了一下:
Hallo.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();
}
}
}
不幸的是,它不起作用。我收到这条消息:
Okt 10, 2018 2:22:04 PM org.jboss.weld.bootstrap.WeldStartup INFO: WELD-000900: 3.0.5 (Final)
Okt 10, 2018 2:22:05 PM org.jboss.weld.bootstrap.WeldStartup startContainer INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Okt 10, 2018 2:22:05 PM org.jboss.weld.environment.se.WeldContainer fireContainerInitializedEvent INFO: WELD-ENV-002003: Weld SE container 5adc2948-acd7-423c-84dc-c1463534c309 initialized
Okt 10, 2018 2:22:05 PM org.jboss.weld.environment.se.WeldContainer shutdown INFO: WELD-ENV-002001: Weld SE container 5adc2948-acd7-423c-84dc-c1463534c309 shut down
我错过了什么?
提前致谢。
CDI 容器工作正常。
Transactional services not available
声明您不在事务管理器下 运行,默认情况下,您(几乎)在应用程序服务器中 运行 拥有事务管理器。