我刚刚将Weld从2.4.4版本更新到3.0.1。我在应用程序启动时遇到以下错误,但找不到解决方案。我正在使用Weld SE。
Sep 15, 2017 1:25:12 PM org.jboss.weld.xml.BeansXmlHandler error
WARN: WELD-001208: Error when validating file:/(...)/META-INF/beans.xml@7 against xsd. cvc-complex-type.2.4.a: Invalid content was found starting with element 'weld:scan'. One of '{"http://xmlns.jcp.org/xml/ns/javaee":interceptors, "http://xmlns.jcp.org/xml/ns/javaee":decorators, "http://xmlns.jcp.org/xml/ns/javaee":alternatives, "http://xmlns.jcp.org/xml/ns/javaee":scan, "http://xmlns.jcp.org/xml/ns/javaee":trim}' is expected.
beans.xml
包含一个Weld专用标签,以在扫描中包括某些类(因为CDI规范仅支持排除)。<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:weld="http://jboss.org/schema/weld/beans"
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"
bean-discovery-mode="all">
<weld:scan>
<weld:include name="com.company.mypackage"/>
(...)
</weld:scan>
</beans>
我使用以下Maven Weld SE依赖项。
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>3.0.1.Final</version>
</dependency>
您能告诉我该怎么做才能解决这个问题?我已经检查过CDI 2.0 XSD,但还没有找到。也许,CDI现在已支持扫描的包含限制?还是Weld XSD发生了变化?
我已经在bug tracker of Weld上创建了一个票证,以防它是一个错误。
最佳答案
发现了问题-我试图在JIRA issue for CDI (CDI-717)中进行描述。
但总结一下,这不是Weld的问题,而是CDI 2.0 XSD验证文件的问题。
发生了意外更改,其中删除了一行。
这行代码允许任何实现(例如Weld)添加其他元素(来自不同名称空间)并仍通过XSD验证。
仅出于完整性考虑,可以在here (with the link to missing line)中看到以前的XSD文件。
然后,新的为here。
顺便说一句,即使有这些验证警告/错误,您也可以安全地运行应用程序。 Weld注意到了它们,但应该能够处理它们,并且仍在运行您的应用程序。