我正在尝试使用 CDI、DeltaSpike(引导)和 Weld SE 作为 CDI 实现来打包命令行应用程序。从我的 IDE 启动时,应用程序运行良好,但在将应用程序打包到 uber-jar 时收到一条模糊错误消息:
Exception in thread "main" org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument bean must not be null
at org.jboss.weld.util.Preconditions.checkArgumentNotNull(Preconditions.java:40)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:772)
at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:61)
at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:85)
at org.apache.deltaspike.cdise.weld.WeldContainerControl.getContextControl(WeldContainerControl.java:138)
at com.katalystdm.sql.exec.CDIBootstrap.boot(CDIBootstrap.java:13)
at com.katalystdm.sql.exec.Main.main(Main.java:44)
这是 maven-shade-plugin 配置:
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/LICENSE*</exclude>
<exclude>**/NOTICE*</exclude>
</excludes>
</filter>
</filters>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
boot()
功能很简单:
public static <T> T boot(CdiContainer container, Class<T> clazz)
{
container.boot();
ContextControl contextControl = container.getContextControl(); // <-- Exception thrown here!
contextControl.startContexts();
return BeanProvider.getContextualReference(clazz, false);
}
鉴于这在从 IDE 启动时有效,它一定是包装问题,但我不知道原因可能是什么。
一个区别可能是 CDI 在扫描 bean 时会选择什么。在我beans.xml
的应用程序中,我基本上排除了所有包,除了我自己的应用程序:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:weld="http://jboss.org/schema/weld/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1"
bean-discovery-mode="all">
<scan>
<exclude name="com.beust.**"/>
<exclude name="com.google.**"/>
<exclude name="com.opencsv.**"/>
<exclude name="javax.**"/>
<exclude name="oracle.**"/>
<exclude name="org.**"/>
</scan>
</beans>
关于从这里开始的任何想法?