Warning at Weld 3 startup with XSD invalid beans.xml for weld:scan tag

1.4k views Asked by At

I just updated Weld from version 2.4.4 to 3.0.1. I am facing the following error at the application startup and I cannot found a solution. I am using 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.

The beans.xml contains a Weld specific tag to include some classes in the scan (as only exclusion is supported by the CDI specification).

<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>

I use the following Maven Weld SE dependency.

<dependency>
    <groupId>org.jboss.weld.se</groupId>
    <artifactId>weld-se-core</artifactId>
    <version>3.0.1.Final</version>
</dependency>

Could you tell me what should I do to solve this problem? I have checked for a CDI 2.0 XSD but I haven't found any. Perhaps, the include restriction for the scan is now supported natively by CDI? Or perhaps the Weld XSD has changed?

I have created a ticket on the bug tracker of Weld in case it is a bug.

3

There are 3 answers

0
Siliarus On BEST ANSWER

Found the problem - I tried to describe in in JIRA issue for CDI (CDI-717).

But to sum it up here, it's not Weld issue, but rather a problem with CDI 2.0 XSD validation file. There was a unintended change where one line was removed. This line permitted any implementation (e.g. Weld) to add additional elements (from different namespaces) and still pass the XSD validation.

Just for completness, the former XSD file can be seen here (with the link to missing line). The new one is then here.

BTW you are safe to run your application even with these validation warnings/error. Weld notices them, but should be able to deal with them and still run your app.

1
Albert Bos On

The XML is being validated against CDI. You require Weld specific XML, according to https://docs.jboss.org/weld/reference/2.0.1.Final/en-US/html/configure.html your <beans> should look like:

<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">
6
John Ament On

I can't see that I've seen your issue before. I can confirm that weld:scan is still supported in Weld 3, but I'm not sure (assuming you're using SE?) it would be supported in your deployment model.

I used this format, and I don't get your error (but I do get weird IDE warnings using your file) so maybe this fixes it?

<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>

Note that you should also confirm you're on the right version for Jersey, using CDI 2.0's features - https://github.com/jersey/jersey/tree/master/ext/cdi/jersey-weld2-se