前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >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
7630
发布2022-11-06 09:47:03
举报
文章被收录于专栏:10km的专栏

今天启动我的spring-boot项目时报了如下的错误:

代码语言:javascript
复制
***************************
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

意思就是找不到com.google.gson.GsonBuilder.setLenient()方法,gson-2.2.4.jar中的GsonBuilder类确没有这个方法。初步判断这应该是gson库的版本不匹配造成的

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高版本,导致错误发生。 知道了原因,就知道怎么解决了:就要在项目强制使用spring-boot依赖的高版本。 如上面stackoverflow的帖子中的解决办法 ,在项目的pom.xml中添加gson依赖,使高版本生效

代码语言:javascript
复制
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.8.2</version>
		</dependency>

参考资料

《Why do I get Gson builder error when starting a Spring Boot application?》

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-10-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 参考资料
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档