Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

KenjiGoh
KenjiGoh

Posted on • Edited on

     

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)

Gowildfly 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-<version>.tar.gzcd wildfly-<version>/tar -xvzf wildfly-35.0.1.Final.tar.gzcd wildfly-35.0.1.Final/
Enter fullscreen modeExit fullscreen mode

2. Test start the Jboss server

cd wildfly-35.0.1.Final/./bin/standalone.sh
Enter fullscreen modeExit fullscreen mode

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

./bin/standalone.sh -Djboss.http.port=9090
Enter fullscreen modeExit fullscreen mode

Openhttp://localhost:9090 to see this:

Image description

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>
Enter fullscreen modeExit fullscreen mode

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>
Enter fullscreen modeExit fullscreen mode

Add spring-boot-starter-tomcat as provided:

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-tomcat</artifactId>    <scope>provided</scope></dependency>
Enter fullscreen modeExit fullscreen mode

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);    }}
Enter fullscreen modeExit fullscreen mode

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>
Enter fullscreen modeExit fullscreen mode

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>
Enter fullscreen modeExit fullscreen mode

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";    }}
Enter fullscreen modeExit fullscreen mode

4. Start the war package

Build the WAR

mvn clean package
Enter fullscreen modeExit fullscreen mode

Copy the WAR file to JBoss deployments folder

cp target/demo-0.0.1-SNAPSHOT.war $JBOSS_HOME/standalone/deployments/
Enter fullscreen modeExit fullscreen mode

Image description

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!
Enter fullscreen modeExit fullscreen mode

Image description

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full Stack Developer#Node #React #Express #Python #AWS #Java #Serverless
  • Location
    Singapore
  • Education
    Lifetime Schooling
  • Work
    for good food.
  • Joined

More fromKenjiGoh

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp