SpringBoot项目启动报错,提示 gson-2.2.4.jar
包有问题:
***************************
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.gson.GsonAutoConfiguration$StandardGsonBuilderCustomizer.customize(GsonAutoConfiguration.java:90)
The following method did not exist:
com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
The calling method's class, org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration$StandardGsonBuilderCustomizer, was loaded from the following location:
jar:file:/C:/Users/shaonaiyi/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.7.5/spring-boot-autoconfigure-2.7.5.jar!/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration$StandardGsonBuilderCustomizer.class
The called method's class, com.google.gson.GsonBuilder, is available from the following locations:
jar:file:/C:/Users/shaonaiyi/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar!/com/google/gson/GsonBuilder.class
The called method's class hierarchy was loaded from the following locations:
com.google.gson.GsonBuilder: file:/C:/Users/shaonaiyi/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration$StandardGsonBuilderCustomizer and com.google.gson.GsonBuilder
进程已结束,退出代码1
我使用的SpringBoot是2.7.3版本。
在pom.xml中输入依赖,并重新引入即可解决:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>