SpringBoot集成第三方jar包启动报错
背景
对接某第三方jar包,集成到SpringBoot里面跑测试demo,启动报错
报错BUG
2020-03-27 15:50:07.084 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception
java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
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:/maven_repository/cn/coralglobal/coupang-open-api/1.0.13/coupang-open-api-1.0.13.jar!/com/google/gson/GsonBuilder.class
It was loaded from the following location:
file:/D:/maven_repository/cn/coralglobal/coupang-open-api/1.0.13/coupang-open-api-1.0.13.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.gson.GsonBuilder
排查问题
查看了很多资料说是 gson版本冲突什么的,我排除 spring-boot-starter-web 里面的gson还是报错
解决方案
@SpringBootApplication(exclude = {GsonAutoConfiguration.class})
参考链接
SpringBoot排除自动装配某个class来解决jar包冲突
https://my.oschina.net/wangxu3655/blog/3100054
链接地址 link