【发布时间】:2018-05-04 09:29:55
【问题描述】:
我正在尝试在我的 Quartz 应用程序中初始化 CDI-SE 上下文,所以我有以下依赖项(maven):
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.3.4.Final</version>
</dependency>
在我的 JobQuartz 中,我有 execute() 方法,其中包含以下内容:
public void execute(JobExecutionContext context) throws JobExecutionException {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
service = container.instance().select(MyService.class).get();
service.go();
weld.shutdown();
}
但我收到以下错误:
Caused by: java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found
我的项目是一个WAR,所以我把beans.xml文件放在/src/main/webapp/META-INF/里面,看内容:
<?xml version="1.0"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.2" bean-discovery-mode="all">
</beans>
我将文件复制到/src/main/resource/META-INF,但我得到了同样的错误。
【问题讨论】:
-
你如何部署或“启动”这个 WAR?通常,您应该将 Weld SE 与 JAR 一起使用。 WAR 通常是使用标准 Weld/weld-servlet 的服务器/servlet(两者都不是您手动启动的)。
-
附带说明(不能解决您的问题),
WeldContainer实现了Instance,因此您应该能够执行container.select(MyService.class)。WeldContainer.instance()方法已在较新版本中被弃用。 -
@Siliarus,我在 JBoss 中部署我的战争,但石英我需要一些石英没有的范围,所以我使用了焊接 se
-
beans.xml 必须在
/src/main/webapp/WEB-INF/,而不是/src/main/webapp/META-INF/ -
我在这个路径中也有 beans.xml,但我得到了同样的错误
标签: java cdi weld jboss-weld weld-se