<div dir="ltr"><div>Hello devs,<br></div><div><div><br>I have a wildfly war application at hands, which depends on a jar which starts its own JPA persistence container with Spring. This jar has its own `persistence.xml`, with  only one persistence unit.<br>
In the embedded jar, since there is only one persistence unit, it is injected using a `@PersistenceContext` without a unit name. Furthermore, the objects having such fields are not EJBs, they are simple Spring beans...<br>
<br>On the other hand, the application has also a `persistence.xml` with two persistence units.<br>The code of the application has `@PersistenceContext` fields with a proper `unitName`, which is mandatory since there are two of them.<br>
<br>Now, when I start my application, Wildfly (specifically the jpa module) scans the code from the jar and chokes on the `@PersistenceContext` without unitNames of my Spring beans:<br><br>    DEBUG [org.jboss.as.jpa.messages] (MSC service thread 1-1) persistence unit search for unitName=null referenced from class=the.spring.Bean (annotation=@javax.persistence.PersistenceContext() on void the.spring.Bean.setEntityManager(javax.persistence.EntityManager))<br>
<br><br>To cope with this, I would like to exclude the jar: In TomEE there is a mean to exclude a jar explicitly from being scanned, but I cannot find a similar functionnality in WildFly.<br>I have tried the following configurations without success:<br>
<br> - `jboss-deployment-structure.xml` which is read but without noticeable effect:<br><br>        &lt;jboss-deployment-structure xmlns=&quot;urn:jboss:deployment-structure:1.2&quot;&gt;<br>          &lt;deployment&gt;<br>
            &lt;exclusions&gt;<br>              &lt;module name=&quot;deployment.jee-app.war.spring-app.jar&quot; /&gt;<br>              &lt;!-- I have also tried the following --&gt;<br>              &lt;!-- &lt;module name=&quot;jee-app.war.spring-app.jar&quot; /&gt; --&gt;<br>
              &lt;!-- &lt;module name=&quot;spring-app.jar&quot; /&gt; --&gt;<br>            &lt;/exclusions&gt;<br>          &lt;/deployment&gt;<br>        &lt;/jboss-deployment-structure&gt; <br><br> - `jboss-scanning.xml` which seems to be ignored<br>
<br>        &lt;scanning xmlns=&quot;urn:jboss:scanning:1.0&quot;&gt;<br>          &lt;path name=&quot;jee-app.war/WEB-INF/lib&quot;&gt;<br>            &lt;exclude name=&quot;spring-app.jar&quot; /&gt;<br>          &lt;/path&gt;<br>
        &lt;/scanning&gt;<br><br><br>Both of these files are in the WEB-INF folder of my war application.<br><br>Of course, I cannot modify the spring-app.jar (would be too easy...)<br><br>Needless to say, I have spend a considerable amount of time in the WildFly doc and on Google without finding anything else than exluding subsystems, or overriding locally modules of WildFly...<br>
<br>Thanks for your help!<br><br>Juan Manuel<br><br></div><div>PS: This question is also posted on StackOverflow: <a href="http://stackoverflow.com/q/22932015/3509723">http://stackoverflow.com/q/22932015/3509723</a><br><br>
</div></div></div>