每当我运行 mvn clean install 时,我都会收到以下错误,并且不会部署到 WildFly 服务器。
Failed to execute goal deploy: {"WFLYCTL0062: Composite
operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"courese-api-app-0.0.1-SNAPSHOT.war\".component.\"jakarta.servlet.http.HttpServlet$NoBodyAsyncContextListener\".WeldInstantiator" => "Failed to start service
[ERROR] Caused by: org.jboss.weld.resources.spi.ResourceLoadingException: Error while loading class jakarta.servlet.http.HttpServlet$NoBodyAsyncContextListener
[ERROR] Caused by: java.lang.IncompatibleClassChangeError: jakarta.servlet.http.HttpServlet and jakarta.servlet.http.HttpServlet$NoBodyAsyncContextListener disagree on InnerClasses attribute"}}}}
使用WildFly-4.0.0.Final
Pom文件如下:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<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>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
请告知我的所有依赖项是否正确,我在堆栈溢出上找不到任何有帮助的解决方案。
我的执行详情如下:
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
我设法通过在主应用程序中扩展 SpringBootServletInitializer 并添加类型为 SpringApplicationBuilder 的覆盖方法 configure
来解决这个问题@SpringBootApplication
public class CoureseApiAppApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(CoureseApiAppApplication.class, args);
}
//If you need a traditional war deployment we need to extend the SpringBootServletInitializer
//This helps us deploy war files to Jboss containers
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) {
return springApplicationBuilder.sources(CoureseApiAppApplication.class);
}
}
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
我通过将以下排除添加到 spring-boot-starter-web 来解决此错误。如下图。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>