我试图在我的 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
,但我得到了同样的错误。