我正在尝试使用CDI,DeltaSpike(引导程序)打包命令行应用程序,使用Weld SE作为CDI实现。从我的IDE启动时,应用程序运行正常,但在将应用程序打包到超级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在扫描豆子时会有所不同。在我的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>
关于从哪里开始的任何想法?
答案 0 :(得分:0)
我发现了问题的解决方案。问题是beans.xml
文件中定义的排除项过于宽泛。由于在扫描时导致CDI错误的几个依赖库,我排除了org.**
下的所有内容。具体而言,CDI扫描org.apache.deltaspike
包非常重要。在我的具体案例中,工作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.kelman.**"/>
<exclude name="com.opencsv.**"/>
<exclude name="javax.**"/>
<exclude name="oracle.**"/>
<exclude name="org.apache.commons.**"/>
<exclude name="org.honton.**"/>
<exclude name="org.jboss.**"/>
<exclude name="org.skife.**"/>
<exclude name="org.slf4j.**"/>
</scan>
</beans>