3

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.

Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82

3 Answers3

2

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.

Siliarus
  • 6,393
  • 1
  • 14
  • 30
0

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

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
John Ament
  • 11,595
  • 1
  • 36
  • 45
  • I use SE version with the Jersey plugin. It was working fine without warning on v2. I'll give a try to your version anyway. – Nicolas Henneaux Sep 23 '17 at 06:23
  • It'd be good to see a full list of your dependencies, as well as how you bootstrap Weld. CDI 2.0 introduces a full SE mode, so you may not need everything, or there may be other changes you should consider. – John Ament Sep 23 '17 at 12:26
  • I got the same error with your `beans.xml`. It is not related to the Jersey plugin but to the Weld version, I have updated my question to get this more clear. – Nicolas Henneaux Sep 26 '17 at 06:17
  • The Weld guys have raised a spec issue, looks like we have removed something. However, you shouldn't need the `` stanza any longer. Can you try without it? – John Ament Sep 26 '17 at 17:01
  • I need it for the application I am developing to avoid scanning all the fat jar where it is bundled. – Nicolas Henneaux Sep 26 '17 at 17:04
  • So you're using something like maven shade plugin to build the binary? – John Ament Oct 05 '17 at 12:11
-1

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">
Albert Bos
  • 2,012
  • 1
  • 15
  • 26