The open source WildFly Application Server (WildFly AS) is an upstream project of the commercial JBoss EAP (Enterprise Application Server). This means that JBoss EAP is based on WildFly AS, and you will probably know how to deploy to JBoss EAP once you learn how to deploy applications to WildFly AS.

In today’s article, I’m going to introduce how to deploy a Spring Boot application to the WildFly application server.

WildFly

Start WildFly Application Server

This article will use the latest stable version of WildFly 26.1.2 Final as an example.

  1. Go to WildFly Downloads to download the latest stable version and unzip

    Suppose we extract wildfly-26.1.2.Final.zip to the G:\wildfly-26.1.2.Final directory.

  2. Open the Command Prompt window and go to the decompressed folder

    1
    
    cd /d G:\wildfly-26.1.2.Final
    
  3. Create administrator account

    1
    
    bin\add-user.bat
    

    Suppose we set the account as wildfly and the password as wi1df1y!.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    What type of user do you wish to add?
    a) Management User (mgmt-users.properties)
    b) Application User (application-users.properties)
    (a): a
    
    Enter the details of the new user to add.
    Using realm 'ManagementRealm' as discovered from the existing property files.
    Username : wildfly
    Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
    - The password should be different from the username
    - The password should not be one of the following restricted values {root, admin, administrator}
    - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
    Password : wi1df1y!
    Re-enter Password : wi1df1y!
    What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]:
    About to add user 'wildfly' for realm 'ManagementRealm'
    Is this correct yes/no? yes
    Added user 'wildfly' to file 'G:\wildfly-26.1.2.Final\standalone\configuration\mgmt-users.properties'
    Added user 'wildfly' to file 'G:\wildfly-26.1.2.Final\domain\configuration\mgmt-users.properties'
    Added user 'wildfly' with groups  to file 'G:\wildfly-26.1.2.Final\standalone\configuration\mgmt-groups.properties'
    Added user 'wildfly' with groups  to file 'G:\wildfly-26.1.2.Final\domain\configuration\mgmt-groups.properties'
    Is this new user going to be used for one AS process to connect to another AS process?
    e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server Jakarta Enterprise Beans calls.
    yes/no? no
    Press any key to continue . . .
    
  4. Start WildFly AS in standalone mode

    1
    
    bin\standalone.bat --debug
    

    Adding --debug will additionally LISTEN Port 8787 to allow IDE tools to debug the application via Attach.

  5. Open WildFly AS default home page: http://127.0.0.1:8080/

    WildFly default home page

  6. Open WildFly AS console: http://127.0.0.1:9990/ (Account: wildfly , Password: wi1df1y! )

    WildFly console

Quickly create a new project using Spring Boot Initializr

  1. Please use the following parameters to create your project

    spring boot project

    You can also create it quickly by clicking here.

  2. Write a HomeController and simply respond with a Hello World string

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    package com.duotify.app1.controllers;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
    * HomeController
    */
    @RestController
    @RequestMapping("/")
    public class HomeController {
        public HomeController() {
        }
    
        @GetMapping
        public String getString() {
            return "Hello World";
        }
    }
    
  3. Adjust the src\main\resources\application.properties property file.

    Since WildFly AS by default occupies Port 8080, which happens to conflict with the Port 8080 used by the Tomcat application server built into Spring Boot. Therefore, it is recommended that you adjust the server.port attribute to 8081.

    1
    
    server.port=8081
    
  4. Start Tomcat Application Server

    Open your browser and request http://localhost:8081/.

    At this point you should see a simple Hello World line on the screen, which means Spring Boot is working properly!

    Hello World

  5. Initializing Git Version Control

    1
    2
    3
    4
    5
    
    curl -sL https://www.gitignore.io/api/java,maven > .gitignore
    
    git init
    git add .
    git commit -m "Initial commit"
    
  1. Create a src/main/webapp/WEB-INF/jboss-web.xml file in the project.

    1
    2
    3
    4
    
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
        <context-root>/</context-root>
    </jboss-web>
    
  2. Exclude ch.qos.logback:logback-classic from the spring-boot-starter-web dependency.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>logback-classic</artifactId>
            <groupId>ch.qos.logback</groupId>
        </exclusion>
    </exclusions>
    </dependency>
    

    spring-boot-starter-web dependency

    If you do not exclude logback-classic, you will see the following error when you deploy.

    1
    2
    3
    
    {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"app1-0.0.1-SNAPSHOT.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/G:/wildfly-26.1.2.Final/modules/system/layers/base/org/slf4j/impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Slf4jLoggerFactory
        Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/G:/wildfly-26.1.2.Final/modules/system/layers/base/org/slf4j/impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Slf4jLoggerFactory
        Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/G:/wildfly-26.1.2.Final/modules/system/layers/base/org/slf4j/impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Slf4jLoggerFactory"}}
    
  3. Add the wildfly-maven-plugin plugin to the <build><plugins> section

    1
    2
    3
    4
    5
    
    <plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>3.0.2.Final</version>
    </plugin>
    
  4. Packaging Applications

    1
    
    mvn clean package
    

    A g:\app1\target\app1-0.0.1-SNAPSHOT.war package file will be created.

  5. Deploy the application

    Copy app1-0.0.1-SNAPSHOT.war directly to the G:\wildfly-26.1.2.Final\standalone\deployments folder, and the deployment will be done automatically!

  6. Testing

    Open your browser and request http://127.0.0.1:8080/.

    hello world

    Everything is OK.

Automatically deploy applications to the WildFly application server

Set up Maven’s install lifecycle phase to automatically deploy applications to the WildFly application server.

  1. First set the properties required for WildFly auto-deployment

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    <properties>
    <java.version>17</java.version>
    <maven.test.skip>true</maven.test.skip>
    
    <deploy.wildfly.host>127.0.0.1</deploy.wildfly.host>
    <deploy.wildfly.port>9990</deploy.wildfly.port>
    <deploy.wildfly.username>wildfly</deploy.wildfly.username>
    <deploy.wildfly.password>wi1df1y!</deploy.wildfly.password>
    
    </properties>
    
  2. Add the <executions> and <configuration settings of the wildfly-maven-plugin plugin

    The main purpose of <executions> is to bind the lifecycle phase install to the wildfly:deploy goal, so that the application can be automatically deployed to WildFly AS when you run mvn install in the future.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    <plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>3.0.2.Final</version>
    
    <executions>
        <execution>
        <phase>install</phase>
        <goals>
            <goal>deploy</goal>
        </goals>
        </execution>
    </executions>
    
    <configuration>
        <filename>${project.build.finalName}.war</filename>
        <hostname>${deploy.wildfly.host}</hostname>
        <port>${deploy.wildfly.port}</port>
        <username>${deploy.wildfly.username}</username>
        <password>${deploy.wildfly.password}</password>
    </configuration>
    
    </plugin>
    
  3. Automatically deploy applications to WildFly AS via Maven

    1
    
    mvn clean install
    

    mvn clean install

Reference https://blog.miniasp.com/post/2022/09/14/How-to-Deploy-Spring-Boot-to-WildFly-Application-Server