先放关键错误信息:
Exception encountered during context initialization - cancelling refresh attempt: 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;
An attempt was made to call the method com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder; but it does not exist. Its class, com.google.gson.GsonBuilder, is available from the following locations:
jar:file:/E:/JAVA/greeApp/maven/repository/com/google/code/gson/gson/2.1/gson-2.1.jar!/com/google/gson/GsonBuilder.class
It was loaded from the following location:
file:/E:/JAVA/greeApp/maven/repository/com/google/code/gson/gson/2.1/gson-2.1.jar
本来想简单启动一个eureka注册中心,所以只依赖了一个包spring-cloud-starter-netflix-eureka-server, 然后报的错也非常明显,Gson2.1包中有个setLenient方法找不到, 但是starter不是都自己集成好的依赖包,官方的还能报错。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>spring-cloud-eureka-server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
</dependencies>
</project>
启动类:
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaServer.class)
.web(WebApplicationType.SERVLET)
.run(args);
}
}
先写怎么解决的,排除Gson
@SpringBootApplication(exclude = {GsonAutoConfiguration.class})
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaServer.class)
.web(WebApplicationType.SERVLET)
.run(args);
}
}
思考1:是不是版本太低了?
换上3.0.3最新版,还是报错。为什么,看不懂
本文暂时没有评论,来添加一个吧(●'◡'●)