首页 > 编程语言 >java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder

java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder

时间:2023-02-07 17:46:34浏览次数:58  
标签:5.3 java 21 springframework google beans GsonBuilder org gson

引入第三方的工具类,重新启动项目就会奇奇怪怪的报错。加载不到gson类。一开始以为是没有加载到,各种引入,清理问题依然存在。直到仔细看报错信息,里面是spring的类报错,才意识到可能是gson版本冲突了,仔细排查是工具类的版本过低导致的。简单点的办法把工具类里的去掉,但是改动很大,只能想其他办法。

 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gsonBuilder' defined in class path resource [org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.google.gson.GsonBuilder]: Factory method 'gsonBuilder' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.21.jar:5.3.21]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.1.jar:2.7.1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.1.jar:2.7.1]
	at com.example.aoa.AoaApplication.main(AoaApplication.java:12) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.7.1.jar:2.7.1]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.google.gson.GsonBuilder]: Factory method 'gsonBuilder' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.21.jar:5.3.21]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.21.jar:5.3.21]
	... 23 common frames omitted
Caused by: java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
	at org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration$StandardGsonBuilderCustomizer.customize(GsonAutoConfiguration.java:90) ~[spring-boot-autoconfigure-2.7.1.jar:2.7.1]
	at org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.lambda$gsonBuilder$0(GsonAutoConfiguration.java:49) ~[spring-boot-autoconfigure-2.7.1.jar:2.7.1]
	at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_144]
	at org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.gsonBuilder(GsonAutoConfiguration.java:49) ~[spring-boot-autoconfigure-2.7.1.jar:2.7.1]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.21.jar:5.3.21]
	... 24 common frames omitted
Caused by: java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
	at java.lang.invoke.MethodHandleNatives.resolve(Native Method) ~[na:1.8.0_144]
	at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975) ~[na:1.8.0_144]
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000) ~[na:1.8.0_144]
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1394) ~[na:1.8.0_144]
	at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1750) ~[na:1.8.0_144]
	at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477) ~[na:1.8.0_144]
	... 33 common frames omitted

  解决方法是添加注解@EnableAutoConfiguration,告诉SpringBoot程序跳过GSON的自动配置

@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.class})

  

标签:5.3,java,21,springframework,google,beans,GsonBuilder,org,gson
From: https://www.cnblogs.com/besehen/p/17099277.html

相关文章

  • 谷歌关键词是怎么排名的?google关键词优化
    本文主要分享关于谷歌排名算法的一些分析以及谷歌关键词优化的细节。本文由光算创作,有可能会被修改和剽窃,我们佛系对待这种行为吧。谷歌关键词排名是指确定网站在搜索引擎结......
  • 【android】Android开发中Gson对象@SerializedName 注解的使用
    当我们使用Gson解析json数据时都会创建一个对应实体类,有时候json数据里面的字段是java关键词或者json数据里面的字段太简单,我们想在实体类中自定义字段名,这时就可以用@Ser......
  • Casbin: 连续3年参加Google Summer of Code的开源授权技术领导者
    Casbin是一个开源的授权解决方案,很自豪的宣布它已经连续三年参加GoogleSummerofCode(GSoC)项目。Casbin是实现访问控制和授权管理的最受欢迎的开源项目之一。该项目广泛应......
  • Casbin: 连续3年参加Google Summer of Code的开源授权技术领导者
    Casbin是一个开源的授权解决方案,很自豪的宣布它已经连续三年参加GoogleSummerofCode(GSoC)项目。Casbin是实现访问控制和授权管理的最受欢迎的开源项目之一。该项目广泛......
  • ChatGPT对Google的挑战这么大么?
    微软对ChatGPT的表现,是跟好几年没闻过肉味的狼一样,铁了心要玩命的开薅,把对OpenAI的投资当成三十年来最有回报的项目。在裁员一万背景下,向OpenAI追加100亿美元投资,占股49%,同......
  • Google XSS Game
    XSSgame(xss-game.appspot.com)这是一款谷歌的XSS游戏,总共有6个级别Level1无需转义,直接编辑URL栏或者搜索框中都可以执行<script>alert(1)</script>Leve......
  • Google的三架马车--Google File System (GFS)
    背景介绍国际方面,数据库理论研究起步于20世纪60年代,并于20世纪70年代开始产业化,逐步形成了成熟的IOE(IBM提供硬件,Oracle提供数据库软件,EMC提供存储介质)应用模式,开始占领全......
  • Google的三架马车--Google MapReduce
    背景介绍国际方面,数据库理论研究起步于20世纪60年代,并于20世纪70年代开始产业化,逐步形成了成熟的IOE(IBM提供硬件,Oracle提供数据库软件,EMC提供存储介质)应用模式,开始占领全......
  • 爬google podcast 笔记
    问题1https://stackoverflow.com/questions/57217924/pyppeteer-errors-browsererror-browser-closed-unexpectedlyexportno_proxy=localhost,127.0.0.1......
  • Guava:google公司开发的一款Java类库扩展工具包
    Guava是google公司开发的一款Java类库扩展工具包文档https://github.com/google/guavahttps://github.com/google/guava/wikihttps://guava.dev/releases/snapshot-jre......