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

前端 未结 5 645
旧时难觅i
旧时难觅i 2020-12-28 14:36

I have downloaded eclipse and installed the spring suit into it. I have written a JPA based Rest application by following one of the spring.io guides. When I try to run it a

5条回答
  •  离开以前
    2020-12-28 15:06

    I faced the same problem and had to waste a lot of time trying to fix this.

    The problem arises due to the version mismatch of the Gson library from existing dependencies already included in your project with that of Spring Boot's default one.

    The easiest fix of this problem (that worked for me) is to replace each occurrence of the

    @EnableAutoConfiguration
    

    tag with

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

    which basically tells the Spring boot application to skip auto configuration for Gson.

    This solution also applies to any other class that might create the same problem. You just need to add the name of each such conflicting class to the exclude attribute of EnableAutoConfiguration.

提交回复
热议问题