November 1, 2017

Add Spring 4 as JBoss Module in Wildfly 10

In order to avoid pack all required JARs of Spring with my web applications, I create a module, using the great JBoss Modules framework (which is already used by Wildfly). Then I can reference this framework, without the need to pack all these JARs inside my web applications (EAR/WAR).

Create Spring module

1. Go to WildFly home directory:

$ cd /home/torun/jboss/wildfly/wildfly-10.0.0.Final

2. Create Spring module directory structure:

$ mkdir -p modules/org/springframework/4.3.12.RELEASE

3. Inside this new directory, create module.xml file with this content:

<module xmlns="urn:jboss:module:1.3" name="org.springframework" slot="4.3.12.RELEASE">
  <resources>
    <!--<resource-root path="org.aspectj.matcher-1.7.4.jar"/>-->
    <resource-root path="aopalliance-1.0.jar"/>
    <resource-root path="aspectjrt-1.8.10.jar"/>
    <resource-root path="aspectjtools-1.8.10.jar"/>
    <resource-root path="aspectjweaver-1.8.10.jar"/>
    <resource-root path="spring-aop-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-aspects-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-beans-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-context-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-context-support-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-core-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-expression-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-tx-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-web-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-webmvc-4.3.12.RELEASE.jar"/>
    <resource-root path="spring-webmvc-portlet-4.3.12.RELEASE.jar"/>
    <!--
    <resource-root path="spring-jdbc-4.3.10.RELEASE.jar"/>
    <resource-root path="spring-orm-4.3.10.RELEASE.jar"/>
    <resource-root path="spring-oxm-4.3.10.RELEASE.jar"/>
    -->
  </resources>
 
  <dependencies>
    <module name="javaee.api" export="true"/>
    <module name="org.apache.commons.logging" export="true"/>
    <module name="org.jboss.vfs" export="true"/>
    <module name="org.hibernate" export="true"/>
    <module name="javax.el.api" export="true"/>
    <module name="com.sun.xml.bind" export="true"/>
    <module name="javax.api" export="true"/>
    <module name="javax.enterprise.api" export="true"/>
    
    <module name="javax.faces.api" />  
    <module name="com.sun.jsf-impl" />  
  </dependencies>
</module>

4. Then download and add all the JARs mentioned as “resource-root” inside this new directory.

5. You are DONE with Spring module!!!

Create jboss-deployment-structure.xml

6. Now in your web application source, create the following file META-INF/jboss-deployment-structure.xml with this content:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <deployment>
        <dependencies>
            <module name="org.springframework" slot="4.3.12.RELEASE">
                <imports>
                    <include path="META-INF**" />
                    <include path="org**" />
                </imports>
            </module>
        </dependencies>
    </deployment>
</jboss-deployment-structure>