Configuring module slots in WildFly

This article covers modules slot installation which allows having multiple versions from the same module, grouped in slots.

Before getting started, we recommend that you check the following resources available on this site:

Most of the modules installed in WildFy contain just a single “main” folder under the modules path. For example, Hibernate module name is “org.hibernate” and libraries are contained in the “org.hibernate.main” folder. The main folder is by convention the default library folder which is used for the module, if you do not specify a module slot.

A module slot is just another folder, at the same level of the main folder, where you can place additional modules implementations. For example, supposing that we want to have installed three different driver versions for mySQL driver. So let’s create one (default) main folder and two additional slots named with the JDBC version we want to install.

jboss as 7 configure a module

Then, inside each folder we will place the module.xml declaration and the JDBC driver. for example in the folder “5.21” we will configure the JDBC driver as follows:

<module xmlns="urn:jboss:module:1.0" name="com.mysql" slot="5.21">
   <resources>
     <resource-root path="mysql-connector-java-5.1.21-bin.jar"/>
 
   </resources>

   <dependencies>
      <module name="javax.api"/>
      <module name="javax.transaction.api"/>
    </dependencies>
</module>

The folder 5.20 needs to be adjusted accordingly with the correct “slot” and the JDBC driver.

On the other hand, the “main” folder will contain just the module name specification, since it is meant to be the default module implementation:

<module xmlns="urn:jboss:module:1.0" name="com.mysql">
   <resources>
     <resource-root path="mysql-connector-java-5.1.18-bin.jar"/>
 
   </resources>

   <dependencies>
      <module name="javax.api"/>
      <module name="javax.transaction.api"/>
    </dependencies>
</module>

How to use a module slot

In order to use a non-default implementation of a module, all we have to do is adding the slot element, wherever the module is specified. For example, in the datasource configuration, the module name is specified into the drivers stanza:

<drivers>
         <driver name="mysql" module="com.mysql" slot="5.21"/>
</drivers>
Found the article helpful? if so please follow us on Socials