相关文章推荐
彷徨的仙人掌  ·  Java ...·  1 月前    · 
踏实的鸡蛋面  ·  android ...·  3 月前    · 
大方的泡面  ·  【2023/05/20】Visual ...·  1 年前    · 

引入spring-cloud-starter-netflix-eureka-client的3.1.3版本,启动时报java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder错误

因为eureka3.1.3中引入gson的是2.1版本,在GsonBuilder类中没有setLenient方法,所以报错。

解决方式,1.排除springBoot中的GsonAutoConfiguration类

@SpringBootApplication(exclude = {GsonAutoConfiguration.class})

2.更换gson版本

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>${springcloud.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.code.gson</groupId>
                    <artifactId>gson</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.9.0</version>
        </dependency>
java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder 从结构上看,所有的数据(data)最终都可以分解成三种类型: 第一种类型是标量(scalar),也就是一个单独的字符串(string)或数字(numbers),比如"北京"这个单独的词。 第二种类型是序列(sequence),也就是若干个相关的数据按照一定顺序并列在一起,又叫做数组(array 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. 2018-10-12 11:06:23.345 ERROR 9947 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bea... Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: java.lang.invoke.MethodHandleNati...
java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder;
最上面是无法嵌入tomcat容器错误,造成原因如标题所示,解决办法加入依赖 &lt;!-- 持久层框架 类似 hibernate mapper 只是 mybatis springboot  mybatis 可以不用 xml 可用 全注解 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.sitemesh&l...
项目中完成短信发送验证码,用到某平台的SDK接口,结果启动模块时报错,抛出 java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/sonElement; 异常. 开始感觉也没多大毛病.可能就是用它SDK本身用的某个jar包升级了,已经不用或没有这个方法. 第一想到的就是找下项目中 jar 版本入手. 找到是GosnJa
Caused by: java.lang.NoSuchMethodError: com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder; 估计是jar包冲突,加上jar包 <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId>
今天在使用Gson 2.0的库时出现了这个错误,但在eclipse中并没有报这个错误。搜索了下,是因为没将gson-2.0.jar放到WEB-INF/lib目录下。将其拖入WEB-INF/lib,问题果然解决了。 但我对此有些疑惑,为什么将gson-2.0.jar放到build path中没用,放到WEB-INF/lib下就行了呢?这可能与Tomcat的内部机制有关系吧。另外我也是过分相信了ec...
java.lang.nosuchmethoderror: com.google.common.base.preconditions.checkargument
python request 报 Connection aborted.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。 ifanda: 一行都爬不了就10054该怎么办