更正您的应用程序的类路径,使其包含 类 org.springframework.boot.autoconfigure.http.HttpMessageConverter 的兼容版本
Correct classpath of your application so it contains compatible versions of classes org.springframework.boot.autoconfigure.http.HttpMessageConverter
更正应用程序的类路径,使其包含 类 org.springframework.boot.autoconfigure.http.HttpMessageConverters 和 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
的兼容版本
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.http.HttpMessageConverters.configurePartConverters(HttpMessageConverters.java:156)
The following method did not exist:
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.getPartConverters()Ljava/util/List;
The calling method's class, org.springframework.boot.autoconfigure.http.HttpMessageConverters, was loaded from the following location:
jar:file:/C:/Users/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.6.3/spring-boot-autoconfigure-2.6.3.jar!/org/springframework/boot/autoconfigure/http/HttpMessageConverters.class
The called method's class, org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter, is available from the following locations:
jar:file:/C:/Users/.m2/repository/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar!/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.class
The called method's class hierarchy was loaded from the following locations:
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter: file:/C:/Users/.m2/repository/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar
org.springframework.http.converter.FormHttpMessageConverter: file:/C:/Users/.m2/repository/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar
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.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
添加 spring-web 依赖项后显示此错误
如您所见,从 Spring 5.2 添加 spring-web
将失败。这是因为 Spring Boot 2.6.x 使用 Spring 5.3。永远不要混合来自不同版本框架的模块。不管是哪个框架,因为那会导致奇怪的错误、不兼容错误(像这个)等等...
要修复,请将 spring-web
依赖项替换为 spring-boot-starter-web
以获得正确的版本。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
更正应用程序的类路径,使其包含 类 org.springframework.boot.autoconfigure.http.HttpMessageConverters 和 org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
的兼容版本***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.http.HttpMessageConverters.configurePartConverters(HttpMessageConverters.java:156)
The following method did not exist:
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.getPartConverters()Ljava/util/List;
The calling method's class, org.springframework.boot.autoconfigure.http.HttpMessageConverters, was loaded from the following location:
jar:file:/C:/Users/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.6.3/spring-boot-autoconfigure-2.6.3.jar!/org/springframework/boot/autoconfigure/http/HttpMessageConverters.class
The called method's class, org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter, is available from the following locations:
jar:file:/C:/Users/.m2/repository/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar!/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.class
The called method's class hierarchy was loaded from the following locations:
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter: file:/C:/Users/.m2/repository/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar
org.springframework.http.converter.FormHttpMessageConverter: file:/C:/Users/.m2/repository/org/springframework/spring-web/5.2.3.RELEASE/spring-web-5.2.3.RELEASE.jar
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.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
添加 spring-web 依赖项后显示此错误
如您所见,从 Spring 5.2 添加 spring-web
将失败。这是因为 Spring Boot 2.6.x 使用 Spring 5.3。永远不要混合来自不同版本框架的模块。不管是哪个框架,因为那会导致奇怪的错误、不兼容错误(像这个)等等...
要修复,请将 spring-web
依赖项替换为 spring-boot-starter-web
以获得正确的版本。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>