2017-09-15 138 views
3

我剛剛將版本2.4.4更新至3.0.1。我在應用程序啓動時遇到以下錯誤,我找不到解決方案。我正在使用Weld SE。Weld 3啓動時發出XSD無效beans.xml焊接問題警告:掃描標籤

Sep 15, 2017 1:25:12 PM org.jboss.weld.xml.BeansXmlHandler error 
WARN: WELD-001208: Error when validating file:/(...)/META-INF/[email protected] 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含有焊縫特定標籤以包括在掃描一些類(如僅排除由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上創建了一張票,以防萬一它是一個錯誤。

回答

1

發現了問題 - 我試圖描述在JIRA issue for CDI (CDI-717)

但總結在這裏,這不是焊接問題,而是CDI 2.0 XSD驗證文件的問題。 有一個意外的改變,其中一行被刪除。 此行允許任何實現(例如Weld)添加其他元素(來自不同的名稱空間)並仍然通過XSD驗證。

只是爲了完整性,前面的XSD文件可以看到here (with the link to missing line)。 新的是here

順便說一句,即使有這些驗證警告/錯誤,您仍然可以安全地運行您的應用程序。 Weld注意到它們,但應該能夠處理它們並仍然運行您的應用程序。

-1

XML正在針對CDI進行驗證。您需要焊接特定的XML,根據https://docs.jboss.org/weld/reference/2.0.1.Final/en-US/html/configure.html<beans>應該是這樣的:

<beans xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:weld="http://jboss.org/schema/weld/beans" 
     xsi:schemaLocation=" 
      http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd 
      http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd"> 
+0

將模式位置添加到XML標頭不起作用 –

0

我看不到我以前見過你的問題。我可以確認weld:scan仍然在Weld 3中受支持,但我不確定(假設您使用SE?),它將在您的部署模型中受支持。

我用這種格式,我沒有得到你的錯誤(但我確實得到奇怪的IDE警告使用你的文件),所以也許這可以解決它?

<beans xmlns:weld="http://jboss.org/schema/weld/beans" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="2.0" bean-discovery-mode="all"> <weld:scan> <weld:include name="org.glassfish.jersey.weld.se.WeldRequestScope"/> </weld:scan> </beans>

請注意,您還應該確定你在正確的版本球衣,使用CDI 2.0的功能 - https://github.com/jersey/jersey/tree/master/ext/cdi/jersey-weld2-se

+0

我使用SE版本和Jersey插件。它在v2上沒有任何警告地工作正常。無論如何,我會嘗試一下你的版本。 –

+0

很高興看到您的依賴關係的完整列表,以及您如何自舉Weld。 CDI 2.0引入了完整的SE模式,因此您可能不需要任何東西,或者可能會有其他更改,您應該考慮。 –

+0

我得到了與'beans.xml'相同的錯誤。它與澤西島插件無關,但與Weld版本無關,我已更新了我的問題以更清楚地說明問題。 –