我正在测试 Weld 和 CDI 的行为,但是每当我调用 Weld::shutdown() 时VerifyError
都会引发异常:
Exception in thread "main" java.lang.VerifyError: Bad return type
Exception Details:
Location:
org/jboss/weld/environment/se/WeldSEProvider.getCDI()Ljavax/enterprise/inject/spi/CDI; @38: areturn
Reason:
Type 'org/jboss/weld/environment/se/WeldContainer' (current frame, stack[0]) is not assignable to 'javax/enterprise/inject/spi/CDI' (from method signature)
Current Frame:
bci: @38
flags: { }
locals: { 'org/jboss/weld/environment/se/WeldSEProvider', 'java/util/List' }
stack: { 'org/jboss/weld/environment/se/WeldContainer' }
Bytecode:
0000000: b800 124c 2bb9 0013 0100 9900 0501 b02b
0000010: b900 1401 0004 a000 112b 03b9 0015 0200
0000020: c000 16b8 0017 b0b2 0018 2bb9 0019 0200
0000030: 2ab7 001a 4d2c c600 0f2a b400 072c b800
0000040: 1bc0 000f b02b 03b9 0015 0200 c000 16b8
0000050: 0017 b0
Stackmap Table:
append_frame(@15,Object[#71])
same_frame(@39)
append_frame(@69,Object[#72])
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at javax.enterprise.inject.spi.CDI.findAllProviders(CDI.java:117)
at javax.enterprise.inject.spi.CDI.current(CDI.java:53)
at org.jboss.weld.bootstrap.WeldBootstrap.shutdown(WeldBootstrap.java:651)
at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.shutdown(ForwardingBootstrap.java:44)
at org.jboss.weld.environment.se.ShutdownManager.shutdown(ShutdownManager.java:44)
at org.jboss.weld.environment.se.Weld.shutdown(Weld.java:223)
at org.Main.main(Main.java:15)
我究竟做错了什么?我根本不应该使用 Weld::shutdown 方法吗?
public static void main(String[] args) {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
ImageFileProcessor imageFileProcessor = container.instance().select(ImageFileProcessor.class).get();
System.out.println(imageFileProcessor.openFile("file1.png"));
weld.shutdown();
}
这适用于 Java 8,Weld 依赖项:
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.3.4.Final</version>
</dependency>