[英]How to get a simple Spring Boot app running on WildFly 27?
There are many tutorials on the inte.net, but unfortunately they all have one thing in common: they don't work. inte.net 上有很多教程,但不幸的是它们都有一个共同点:它们不起作用。 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. WildFly 27 全新安装在一台 windows 机器上,使用 add-user.bat 创建用户帐户,使用 standalone.bat 启动 WildFly 并且可以访问端口:9990 上的管理控制台以及端口:8080 上的 WildFly 起始页.
A simple Spring Boot web project is created.创建一个简单的 Spring Boot web 项目。
The pom.xml looks like this: pom.xml 看起来像这样:
<?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: MainApplication class 看起来像这样:
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.编译后,war 被复制到 deployments 文件夹中。 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.在这里,旅程以一系列
NoClassDefFoundError
结束——尽管这些包/类由 spring-webmvc-5.3.23.jar 在 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?有谁知道如何修复这些错误,或者有没有人手头有一个实际可用的 Spring Boot 示例,可以在 WildFly 上正常运行?
Many thanks in advance提前谢谢了
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.正如 WildFly 27 的发行说明中所述,它现在仅支持 Jakarta EE 10。Spring Boot 2.x 以 Jakarta EE 8 API 为目标。 Spring Boot 3.x was recently released which targets the Jakarta EE 9 API's.
Spring 最近发布了针对 Jakarta EE 9 API 的 Boot 3.x。 You should be able to use Spring Boot 3 with WildFly 27.
您应该能够将 Spring Boot 3 与 WildFly 27 一起使用。
As stated in other comments though, Spring Boot is really meant to work as a standalone application/server within itself.正如其他评论中所述, Spring Boot实际上是作为一个独立的应用程序/服务器在其内部工作。 While there is support to work in other servers, I don't think that is the goal of what Spring Boot is.
虽然支持在其他服务器上工作,但我认为这不是 Spring Boot 的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.