SpringCloud最新版环境集成之eureka

前言

本文依托于SpringCloud最新版环境集成-2021年11月
只介绍eureka环境搭建过程。
在SpringCloud的使用过程中我总结为三步曲。

  • 引入spring-cloud-starter相应jar包
  • properties或yml加入相关配置
  • 启动类加上@Enable相关注解

eureka服务端

1.引入jar
<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>
2.properties加入配置
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/
3.启动类加入注解
@EnableEurekaServer

eureka集群

只需要稍微修改properties的eureka的注册地址。

1.eureka1的application.properties
# 向eureka注册的地址,后面服务名称必须为eureka
eureka.client.serviceUrl.defaultZone=http://localhost:10002/eureka/
2.eureka2的application.properties
# 向eureka注册的地址,后面服务名称必须为eureka
eureka.client.serviceUrl.defaultZone=http://localhost:10001/eureka/

问题

1.eureka无法访问
  • eureka的defaultZone服务名称必须是eureka,而不能是你定义的其他名称。
  • eureak的网页是只需要访问http://localhost:10001/的地址,而不需要eureka服务名
2.服务启动报错
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排除掉即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值