我正在搭建JavaEE7中学习CDI的基本环境。我有以下代码用于启动Weld
。只需要启动和关闭即可。
package com.anshbansal;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
public class Main {
public static void main(String[] args) {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
weld.shutdown();
}
}
我正在关注我的控制台。
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/Softs/Programming/Java/Java%20JARs/JBoss%20Weld-2.0.3/jar/weld-se.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/Softs/Programming/Java/Java%20JARs/JBoss%20Weld-2.0.3/jar/weld-servlet.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[main] INFO org.jboss.weld.Version - WELD-000900 2.0.3 (Final)
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
有问题的线路是WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
。这仅仅意味着依赖注入将不起作用。但我不确定问题是什么。我已经添加了weld-se.jar
in my CLASSPATH
。我什至还没有达到初始化对象的程度那么为什么会出现这个问题呢?
Weld的官方文档也给出了我阅读后得到的相同代码这个答案。 “Antonio Goncalves”所著的《Beginning Java EE 7》一书中使用了相同的代码。我已经验证了进口这个 github 位置。那么,如果我使用了正确的类路径并且没有创建任何对象,那么为什么会出现这个问题?
您的设置适合在 Java SE 中学习 CDI。
为了在 Java EE 中使用 CDI,您显然需要一个 Java EE 容器,一个带有main
方法不行。
Weld 只是告诉您事务不可用(因为您没有在 EE 容器中运行),因此任何与事务相关的 CDI 功能都将被禁用。
依赖注入will只要您不尝试注入任何 Java EE 对象或使用任何需要 Java EE 容器的 CDI 功能,就可以在您的情况下工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)