SpringCloud集成(整合)Eureka

SpringCloud集成整合Eureka

思路:先导入eureka依赖,然后运行环境推荐使用jdk1.8的,然后修改配置文件,然后启动服务进行测试,具体步骤如下所示:

一、准备依赖

  • maven方式

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
    
  • gradle方式

    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' //eureka客户端依赖
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' //eureka服务端依赖
    

二、环境要求

jdk1.8

三、修改配置文件

  • 作为服务端(注册中心)的配置:

    spring:
      application:
        name: eureka-server
    server:
      port: 8761
    eureka:
      client:
        register-with-eureka: false #是否将自己也当作服务注册到服务端注册中心,在这里是false
        fetch-registry: false #示是否从Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false。
        service-url:
         defaultZone: http://localhost:8761/eureka #设置注册中心的地址
      instance:
        prefer-ip-address: true
    
    • 注意:作为服务端(注册中心)使用时,启动类上面需要加上**@EnableEurekaServer**注解
  • 作为客户端的配置:

    spring:
      application:
        name: eureka-server
    server:
      port: 8761
    eureka:
      client:
        register-with-eureka: true 
        fetch-registry: false 
        service-url:
         defaultZone: http://localhost:8761/eureka
      instance:
        prefer-ip-address: true
    

四、测试

  1. 先启动eureka服务端(注册中心)服务
  2. 启动客户端服务
  3. 在浏览器输入http://localhost:8761/eureka即可访问查看自己注册的服务
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值