Skip to content

Instantly share code, notes, and snippets.

@ricardozanini
Last active December 9, 2020 03:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardozanini/275bde3420a53595cd9591109d1095a1 to your computer and use it in GitHub Desktop.
Save ricardozanini/275bde3420a53595cd9591109d1095a1 to your computer and use it in GitHub Desktop.
Add a Spring Framework Web Custom module to Wildfly/JBoss/EAP
  1. Create a module.xml file in $JBOSS_HOME/modules/org/springframework/${spring-version}:
<?xml version="1.0"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework" slot="${spring-version}">
    <resources>
            <resource-root path="aopalliance-1.0.jar" />
            <resource-root path="spring-aop-${spring-version}.jar" />
            <resource-root path="spring-beans-${spring-version}.jar" />
            <resource-root path="spring-context-${spring-version}.jar" />
            <resource-root path="spring-context-support-${spring-version}.jar" />
            <resource-root path="spring-core-${spring-version}.jar" />
            <resource-root path="spring-expression-${spring-version}.jar" />
            <resource-root path="spring-web-${spring-version}.jar" />
    </resources>
    <dependencies>
            <module name="org.apache.commons.logging" />
            <module name="javaee.api"/>
            <module name="javax.api" export="true" />
            <module name="javax.servlet.api" />
            <module name="org.jboss.vfs" />
    </dependencies>
</module>

Note Replace ${spring-version} with your desired Spring Framework version.

It's a good practice to maintain different versions in distinct slots. If you wish to maintain only one version, just stick to the maindirectory instead.

  1. Add all the jar files to the module slot directory:
aopalliance-1.0.jar
spring-aop-${spring-version}.jar
spring-beans-${spring-version}.jar
spring-context-${spring-version}.jar
spring-context-support-${spring-version}.jar
spring-core-${spring-version}.jar
spring-expression-${spring-version}.jar
spring-web-${spring-version}.jar
  1. Add the module dependency into your WEB-INF/jboss-deployment-structure.xml file:
<?xml version="1.0" encoding="UTF-8"?>  
<jboss-deployment-structure>  
    <deployment>  
         <dependencies>  
              <module name="org.springframework" slot="${spring-version}" export="true" meta-inf="export"/> 
        </dependencies>  
    </deployment>  
</jboss-deployment-structure>
  1. (Optional) Try using the 3.x+ Servlet version, referenced at WEB-INF/web.xml file:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

Start your server and check the logs. A successful deployment should output something like this:

11:53:23,808 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "spring-web-wildfly-0.0.1-SNAPSHOT.war" (runtime-name: "spring-web-wildfly-0.0.1-SNAPSHOT.war")
11:53:23,821 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
11:53:24,071 INFO  [org.jboss.web] (ServerService Thread Pool -- 55) JBAS018210: Register web context: /spring-web-wildfly-0.0.1-SNAPSHOT
11:53:24,110 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/spring-web-wildfly-0.0.1-SNAPSHOT]] (ServerService Thread Pool -- 55) Initializing Spring root WebApplicationContext
11:53:24,117 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 55) Root WebApplicationContext: initialization started
11:53:24,176 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 55) Refreshing Root WebApplicationContext: startup date [Fri Nov 24 11:53:24 BRST 2017]; root of context hierarchy
11:53:24,217 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 55) Loading XML bean definitions from "/content/spring-web-wildfly-0.0.1-SNAPSHOT.war/WEB-INF/classes/META-INF/spring/context.xml"
11:53:24,456 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 55) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
11:53:24,463 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (ServerService Thread Pool -- 55) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@17ac5835: defining beans [sayHiImpl,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
11:53:24,482 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 55) Root WebApplicationContext: initialization completed in 365 ms
11:53:24,565 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS015859: Deployed "spring-web-wildfly-0.0.1-SNAPSHOT.war" (runtime-name : "spring-web-wildfly-0.0.1-SNAPSHOT.war")
  1. (Optional) to add all your dependencies from a Maven project to a directory (and then copy it to the module dir), use the dependencies Maven plugin: mvn dependency:copy-dependencies. All files will be copied at target/dependency directory.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.springframework" slot="3.2.18" export="true" meta-inf="export"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
<?xml version="1.0"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework"
slot="3.2.18">
<resources>
<resource-root path="aopalliance-1.0.jar" />
<resource-root path="spring-aop-3.2.18.RELEASE.jar" />
<resource-root path="spring-beans-3.2.18.RELEASE.jar" />
<resource-root path="spring-context-3.2.18.RELEASE.jar" />
<resource-root path="spring-context-support-3.2.18.RELEASE.jar" />
<resource-root path="spring-core-3.2.18.RELEASE.jar" />
<resource-root path="spring-expression-3.2.18.RELEASE.jar" />
<resource-root path="spring-web-3.2.18.RELEASE.jar" />
</resources>
<dependencies>
<module name="org.apache.commons.logging" />
<module name="javaee.api"/>
<module name="javax.api" export="true" />
<module name="javax.servlet.api" />
<module name="org.jboss.vfs" />
</dependencies>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Spring Web Application</display-name>
<!-- location of spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/*.xml</param-value>
</context-param>
<!-- the listener that kick-starts Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment