This tutorial assumes you have already set up Java and Maven in your system.
1. Install JBoss (Wildfly)
Gowildfly 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-<version>.tar.gzcd wildfly-<version>/tar -xvzf wildfly-35.0.1.Final.tar.gzcd wildfly-35.0.1.Final/
2. 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
Openhttp://localhost:9090 to see this:
3. Download and package a springboot app
Gostart 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:
<packaging>war</packaging>
Exclude the embedded tomcat:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions></dependency>
Add spring-boot-starter-tomcat as provided:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope></dependency>
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;@SpringBootApplicationpublic 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
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
Add a HTML under resources\templates:
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head> <title>Home Page</title></head><body> <h1 th:text="${message}">Welcome to the Home Page</h1></body></html>
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;@Controllerpublic 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"; }}
4. 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/
5. 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!
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse