赞
踩
本文依托于SpringCloud最新版环境集成-2021年11月
只介绍eureka环境搭建过程。
在SpringCloud的使用过程中我总结为三步曲。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<exclusions>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
</exclusions>
</dependency>
spring.application.name=springcloud-eureka-server
server.port=10001
# 不向eureka注册
eureka.client.register-with-eureka=false
# 不从eureka获取注册信息
eureka.client.fetch-registry=false
# 向eureka注册的地址,后面服务名称必须为eureka
eureka.client.serviceUrl.defaultZone=http://localhost:10001/eureka/
@EnableEurekaServer
只需要稍微修改properties的eureka的注册地址。
# 向eureka注册的地址,后面服务名称必须为eureka
eureka.client.serviceUrl.defaultZone=http://localhost:10002/eureka/
# 向eureka注册的地址,后面服务名称必须为eureka
eureka.client.serviceUrl.defaultZone=http://localhost:10001/eureka/
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/maven-depostitory/com/google/code/gson/gson/2.1/gson-2.1.jar!/com/google/gson/GsonBuilder.class The class hierarchy was loaded from the following locations: com.google.gson.GsonBuilder: file:/D:/maven/maven-depostitory/com/google/code/gson/gson/2.1/gson-2.1.jar Action: Correct the classpath of your application so that it contains a single, compatible version of com.google.gson.GsonBuilder
由于我使用的是最新版的jar包,网络上的教程直接引入 spring-cloud-starter-eureka-server.jar,而我的是spring-cloud-starter-netflix-eureka-server.jar,结果却启动报错。
根据报错发现和gson包有关系,我不需要使用gson包,因此exclusion排除掉即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。