How to ge a simple Spring Boot app running on WildFly?

2,158 views
Skip to first unread message

Pascal Hopper

unread,
Nov 24, 2022, 5:05:46 PM11/24/22
to WildFly
There are many tutorials on the internet, but unfortunately they all have one thing in common: they don't work. The initial situation is as follows:

WildFly 27 is freshly installed on a windows machine, a user account is created with add-user.bat, WildFly is started with standalone.bat and the admin console on port :9990 as well as the WildFly start page on port :8080 are accessible. A simple Spring Boot web project is created.

The pom.xml looks like this:
```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>wildfly-hello-world</artifactId>
    <version>1</version>
    <packaging>war</packaging>
    <name>wildfly-hello-world</name>
    <description>wildfly-hello-world</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
            </plugin>
        </plugins>
    </build>

</project>
```

The MainApplication class looks like this:
```
package com.example.wildflyhelloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.*;

@SpringBootApplication
public class WildflyHelloWorldApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(WildflyHelloWorldApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WildflyHelloWorldApplication.class);
    }
}

@RestController
@RequestMapping
class HelloWorldController {

    @GetMapping
    public String index() {
        return "Hello World";
    }
}
```

After compiling, the war is copied to the deployments folder. And here the journey ends with a series of `NoClassDefFoundError`s - although these packages/classes are provided by spring-webmvc-5.3.23.jar under WEB-INF\lib.

Here is a line excerpt from the log:
```
org.jboss.modules.define] (MSC service thread 1-5) Failed to define class org.springframework.web.servlet.tags.form.AbstractHtmlElementTag in Module "deployment.wildfly-hello-world-1.war" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link org/springframework/web/servlet/tags/form/AbstractHtmlElementTag (Module "deployment.wildfly-hello-world-1.war" from Service Module Loader): javax/servlet/jsp/tagext/DynamicAttributes
```

Does anyone know how to fix these errors, or does anyone have an actual and working Spring Boot example at hand that runs properly on WildFly?

Many thanks in advance

Emmanuel Hugonnet

unread,
Nov 25, 2022, 2:59:41 AM11/25/22
to wil...@googlegroups.com
WildFly 27 is JakartaEE 10 while the SpringBoot version targets JavaEE 8. You need to revert to WildFly 26.1.2.Final.
Cheers,
Emmanuel
> --
> You received this message because you are subscribed to the Google Groups "WildFly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wildfly/94a96d64-2307-4c93-a833-eb2086bfa68en%40googlegroups.com
> <https://groups.google.com/d/msgid/wildfly/94a96d64-2307-4c93-a833-eb2086bfa68en%40googlegroups.com?utm_medium=email&utm_source=footer>.

Chege Kĩnũthia

unread,
Nov 25, 2022, 3:06:38 AM11/25/22
to Emmanuel Hugonnet, wil...@googlegroups.com
Spring boot 3 is now available. It targets JakartaEE 9.

Wei Nan Li

unread,
Nov 25, 2022, 10:09:33 AM11/25/22
to Pascal Hopper, WildFly
Not sure which version you are referring to. Currently I'm working on
resteasy-spring integration with WildFly, and here is a reproducer
that shows some problems you might meet during the deployment process:

- https://github.com/liweinan/SpringWebappContextResource-reproducer

Generally speaking, Spring has its own components container and
maintains its own lifecycles, which cause conflict with CDI and Weld.

You may try to exclude the CDI subsystem and JSF subsystem(which is
Weld JSF in WildFly, and you need to use the Spring supported JSF) to
see if it works in Wildfly. Currently the above producer works for
WildFly 28 SNAPSHOT and Spring 6, and should work for 27 too(though
it's not spring-boot, but it could be modified to work for spring-boot
I guess).
> --
> You received this message because you are subscribed to the Google Groups "WildFly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/94a96d64-2307-4c93-a833-eb2086bfa68en%40googlegroups.com.



--
Cheers,
Wei Nan | JBoss

Pascal Hopper

unread,
Nov 28, 2022, 2:24:28 PM11/28/22
to WildFly
This is the first useful information in a long time. Thank you very much :)
Reply all
Reply to author
Forward
0 new messages