社区首页
>
专栏
>
10km的专栏
>
spring-boot:The following method did not exist: com.google.gson.GsonBuilder.setLenient()
spring-boot:The following method did not exist: com.google.gson.GsonBuilder.setLenient()
10km
发布
于
2022-11-06 09:47:03
385
0
发布
于
2022-11-06 09:47:03
举报
今天启动我的spring-boot项目时报了如下的错误:
***************************
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:
java.lang.invoke.MethodHandleNatives.resolve(Native Method)
The following method did not exist:
com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
The method's class, com.google.gson.GsonBuilder, is available from the following locations:
jar:file:/J:/maven_repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar!/com/google/gson/GsonBuilder.class
The class hierarchy was loaded from the following locations:
com.google.gson.GsonBuilder: file:/J:/maven_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 a single, compatible version of com.google.gson.GsonBuilder
google上找了一下,找到stackoverflow上的如下帖子:
《Why do I get Gson builder error when starting a Spring Boot application?》
知道了原因,
org.springframework.boot:spring-boot-autoconfigure:2.5.6
包中的GsonAutoConfiguration类中引用了
com.google.gson.GsonBuilder.setLenient()
‘方法,应该是较高的gson版本。
我的项目中引用的
org.apache.phoenix:phoenix-core:4.14.0-cdh5.14.2
库也依赖gson 2.2.4库,替换了
spring-boot-autoconfigure
中引用的gson高版本,导致错误发生。