Basic Setup: Run SpringBoot using JBoss (Wildfly)

This tutorial assumes you have already set up Java and Maven in your system. Install JBoss (Wildfly) Go wildfly download page and download the tar file. For example, I downloaded version 35.0.1.Final. Once downloaded, run this to unzip: tar -xvzf wildfly-.tar.gz cd wildfly-/ tar -xvzf wildfly-35.0.1.Final.tar.gz cd wildfly-35.0.1.Final/ Test start the Jboss server cd wildfly-35.0.1.Final/ ./bin/standalone.sh The default port is 8080, you can change port like this: ./bin/standalone.sh -Djboss.http.port=9090 Open http://localhost:9090 to see this: Download and package a springboot app Go start spring and select maven. By default, maven will build jar. We need to use war for JBoss server. Locate your pom.xml and update your build to war: war Exclude the embedded tomcat: org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat Add spring-boot-starter-tomcat as provided: org.springframework.boot spring-boot-starter-tomcat provided Modify the SpringBootApplication Class to extend from SpringBootServletInitializer: import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class MyApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } Do some minimal changes to your springboot app for easier validation: Add ThymeLeaf in pom.xl org.springframework.boot spring-boot-starter-thymeleaf Add a HTML under resources\templates: Home Page Welcome to the Home Page Add a HomeController package com.example.demo.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class HomeController { @GetMapping("/home") public String home(@RequestParam(name = "message", required = false, defaultValue = "Hello, Thymeleaf!") String message, Model model) { model.addAttribute("message", message); return "home"; } } Start the war package Build the WAR mvn clean package Copy the WAR file to JBoss deployments folder cp target/demo-0.0.1-SNAPSHOT.war $JBOSS_HOME/standalone/deployments/ Finally start your demo springboot app with Jboss server! http://localhost:9090/demo-0.0.1-SNAPSHOT/home?message=Springboot%20is%20running%20on%20jboss%20now!

Feb 20, 2025 - 07:14
 0
Basic Setup: Run SpringBoot using JBoss (Wildfly)

This tutorial assumes you have already set up Java and Maven in your system.

  1. Install JBoss (Wildfly) Go wildfly download page and download the tar file. For example, I downloaded version 35.0.1.Final.

Image description

Once downloaded, run this to unzip:

tar -xvzf wildfly-.tar.gz
cd wildfly-/

tar -xvzf wildfly-35.0.1.Final.tar.gz
cd wildfly-35.0.1.Final/

  1. Test start the Jboss server
cd wildfly-35.0.1.Final/
./bin/standalone.sh

The default port is 8080, you can change port like this:

./bin/standalone.sh -Djboss.http.port=9090

Open http://localhost:9090 to see this:

Image description

  1. Download and package a springboot app Go start spring and select maven. By default, maven will build jar. We need to use war for JBoss server. Locate your pom.xml and update your build to war:
war

Exclude the embedded tomcat:


    org.springframework.boot
    spring-boot-starter-web
    
        
            org.springframework.boot
            spring-boot-starter-tomcat
        
    

Add spring-boot-starter-tomcat as provided:


    org.springframework.boot
    spring-boot-starter-tomcat
    provided

Modify the SpringBootApplication Class to extend from SpringBootServletInitializer:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

Do some minimal changes to your springboot app for easier validation:
Add ThymeLeaf in pom.xl

        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        

Add a HTML under resources\templates:




    Home Page


    

Welcome to the Home Page

Add a HomeController

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HomeController {

    @GetMapping("/home")
    public String home(@RequestParam(name = "message", required = false, defaultValue = "Hello, Thymeleaf!") String message, Model model) {
        model.addAttribute("message", message);
        return "home";
    }
}
  1. Start the war package Build the WAR
mvn clean package

Copy the WAR file to JBoss deployments folder

cp target/demo-0.0.1-SNAPSHOT.war $JBOSS_HOME/standalone/deployments/

Image description

  1. Finally start your demo springboot app with Jboss server!
http://localhost:9090/demo-0.0.1-SNAPSHOT/home?message=Springboot%20is%20running%20on%20jboss%20now!

Image description