Why do I get Gson builder error when starting a Spring Boot application?

I would write this as a comment, but I still haven’t got enough rep.

The problem must be with your dependencies. What happens here is that SpringBoot loads the GsonAutoConfiguration @Configuration class, which tries to call GsonBuilder‘s setLenient() method. SpringBoot already has the correct gson jar set as a dependency which should automatically be included in your build; however, explicitly specifying a dependency to gson would override the dependency brought by SpringBoot. Apparently, setLenient() still did not exist in the version of gson that you are using.

The best you can do is either remove the explicit dependency to gson from your pom.xml (or build.gradle, or whatever else you use), or update it to match the one which is expected by the SpringBoot version you are using.

This is the most recent version of gson, in case you are using a recent version of SpringBoot:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
</dependency>

EDIT: it could also happen that even if you don’t declare gson explicitly in your build, another one of your dependencies is using an older version of it, and it overrides the version which SpringBoot expects. In that case, instead of trying to brute-force through the problem, I would suggest to go through all your dependencies and make sure that the versions line up. Going through the dependencies and their versions listed in Maven Central might be a good idea.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)