Wildfly 10.1 CDI / WELD not working for @Any (war inside ear referencing jar in module)
Asked Answered
B

0

6

My local instance interFaces (in my java war web-app) is not being injected from a "cdi-able (thejarwithbeansxml.jar)" (beans.xml) jar referenced from my jboss-deployment-structure.xml (referencing the module).

Please see below configuration;

theapp.ear

--- META-INF --> jboss-deployment-structure.xml

--- bunch of ejb's

--- bunch of wars

--- webapp.war (please see module configuration)

the jboss-deployment-structure.xml body in (theapp.ear->META-INF)

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">

<!-- Make sub deployments isolated by default, so they cannot see each others classes without a Class-Path entry -->
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>

<deployment>
    <dependencies>
        ...
</deployment>


<sub-deployment name="webapp.war">
    <dependencies>
        <module name="com.mymoduletest1"
                meta-inf="import"
                services="import"
                slot="main"
                annotations="false"
                export="true"
                optional="false">
            <imports>
                <include-set>
                    <path name="META-INF"/>
                    <path name="META-INF/beans.xml"/>
                    <path name="META-INF/*"/>
                </include-set>
            </imports>
        </module>
</sub-deployment>
</jboss-deployment-structure>

module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mymoduletest1">

<resources>
    <resource-root path="thejarwithbeansxml.jar"/>
</resources>

<dependencies>
    <module name="someothermodule" export="true">
        <imports>
            <include path="META-INF"/>
        </imports>
    </module>
</dependencies>
</module>

webapp.war (deployed as part of the ear)

Has a Rest web service class where the injection occurs as follows; //expecting to have subclasses ofIActionBaseinjected from module com.mymoduletest1. @Inject @Any private Instance<IActionBase> interFaces;

After reading the Wildfly documentation again and again, I seemed to be following all the rules and that this type of functionality is supported by Wildfly. Example; Snippet from JBoss

When I create a sub-class of IActionBase that resides inside the webapp.war, there is no issues. Any suggestions would be greatly appreciated.

Additional Test Code

The code below (within the webapp.war);

java.io.InputStream schemaIS = Class.forName("com.fluidattica.test.TestCrazy").getClassLoader().getResourceAsStream("META-INF/beans.xml");

            int readVal = -1;
            while((readVal = schemaIS.read()) > -1)
            {
                System.out.print((char)readVal);
            }

Yielded the following result (which indicates the beans.xml is visible and loaded);

19:21:47,335 INFO  [stdout] (default task-1) <?xml version="1.0" encoding="UTF-8"?>
19:21:47,337 INFO  [stdout] (default task-1) <!-- This file can be an empty text file (0 bytes) -->
19:21:47,339 INFO  [stdout] (default task-1) <!-- We're declaring the schema to save you time if you do have to configure
19:21:47,340 INFO  [stdout] (default task-1)    this in the future -->
19:21:47,342 INFO  [stdout] (default task-1) <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19:21:47,342 INFO  [stdout] (default task-1)        xsi:schemaLocation="
19:21:47,344 INFO  [stdout] (default task-1)         http://java.sun.com/xml/ns/javaee
19:21:47,345 INFO  [stdout] (default task-1)         http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
19:21:47,345 INFO  [stdout] (default task-1) 
19:21:47,345 INFO  [stdout] (default task-1) </beans>
Blackdamp answered 1/9, 2017 at 12:43 Comment(1)
I did a test with Tomcat-8 using weld-servlet 2.4.4.Final, and it worked.Blackdamp

© 2022 - 2024 — McMap. All rights reserved.