欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Springboot整合Gson报错问题解决过程

程序员文章站 2022-03-20 17:54:58
在springboot 中依赖gson,项目启动时报错:***************************application failed to start******************...

在springboot 中依赖gson,项目启动时报错:

***************************
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:/d:/8_maven/mvnrepo/com/google/code/gson/gson/2.5/gson-2.5.jar!/com/google/gson/gsonbuilder.class

it was loaded from the following location:

  file:/d:/8_maven/mvnrepo/com/google/code/gson/gson/2.5/gson-2.5.jar


action:

correct the classpath of your application so that it contains a single, compatible version of com.google.gson.gsonbuilder

解决办法:

将pom中依赖的gson版本更换为2.6以上即可

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
  <groupid>com.google.code.gson</groupid>
  <artifactid>gson</artifactid>
  <version>2.8.6</version>
</dependency>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。