SpringBoot中pom引入gson异常

Posted cat-fish6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot中pom引入gson异常相关的知识,希望对你有一定的参考价值。

 在pom中引入gson依赖,启动spring boot项目中报错

Description:

An attempt was made to call the method com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder; but it does not exist. Its class, com.google.gson.GsonBuilder, is available from the following locations:

    jar:file:/D:/work/code/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar!/com/google/gson/GsonBuilder.class

It was loaded from the following location:

    file:/D:/work/code/.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 a single, compatible version of com.google.gson.GsonBuilder
开始以为jar包冲突,查询各个pom发现并没有重复依赖,最后将2.2.4版本换为2.6版本后启动正常

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6</version>
<!--<scope>compile</scope>-->
</dependency>

以上是关于SpringBoot中pom引入gson异常的主要内容,如果未能解决你的问题,请参考以下文章

Log4j 2.x 在Springboot应用中如何配置

springboot配置fastjson

springboot maven项目中,pom文件引入自定义jar包,例如百度sdk,2步搞定

maven项目(引入依赖失败, pom.xml 报错爆红)

Springboot引入本地jar时打包

SpringBoot不通过私服方式引入第三方jar包