Reputation: 1254
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 an 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
Upvotes: 3
Views: 4744
Reputation: 17760
As noted in the release notes for WildFly 27, it now only supports Jakarta EE 10. Spring Boot 2.x is targets Jakarta EE 8 API's. Spring Boot 3.x was recently released which targets the Jakarta EE 9 API's. You should be able to use Spring Boot 3 with WildFly 27.
As stated in other comments though, Spring Boot is really meant to work as a standalone application/server within itself. While there is support to work in other servers, I don't think that is the goal of what Spring Boot is.
Upvotes: 3