- 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 main
directory instead.
- 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
- 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>
- (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")
- (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 attarget/dependency
directory.