我无法进行焊接工作 下面是我在Java SE中的简单CDI测试
1)测试
public class RuntimeEnvironmentProducerTest {
@Inject
RuntimeEnvironmentProducer environment;
public void runTest(){
if(environment != null){
System.out.println("environment ok");
}else{
System.out.println("environment not ok");
}
}
}
2)主要
public class MainTests {
public static void main(String[] args) throws IOException {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
RuntimeEnvironmentProducerTest runtimeEnvironmentProducerTest
= container.instance().select(RuntimeEnvironmentProducerTest.class).get();
runtimeEnvironmentProducerTest .runTest();
weld.shutdown();
}
}
3)输出:
12:28:12.939 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
12:28:13.024 [main] INFO org.jboss.weld.Version - WELD-000900 1.1.13 (Final)
Exception in thread "main" java.lang.ClassCastException: org.jboss.weld.bootstrap.WeldBootstrap cannot be cast to org.jboss.weld.bootstrap.api.CDI11Bootstrap
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:120)
at producersTests.MainTests.main(MainTests.java:17)
有人能给我一些提示吗?
答案 0 :(得分:0)
您可以通过重新排序Maven依赖项来解决此问题。将weld-se
置于顶部。