springcloud学习-03 Eureka【周阳springcloud2020学习笔记】

单机版注册中心

1.创建module

2.pom引入依赖:注意是server!

    <!--eureka-server-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>

3.yml配置

    server:
      port: 7001

    eureka:
      instance:
        hostname: localhost #eureka服务端的实例名字
      client:
        allow-redirects: false # 是否向注册中心注册本服务:true为是。注册中心不需要将自己注册进去
        fetch-registry: false # false表示自己是注册中心,职责是维护服务实例,并不需要去检索服务
        service-url:
          #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址,多个时用逗号隔开
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

4.主启动类:

@EnableEurekaServer
@SpringBootApplication
@EnableEurekaServer //服务端:注册中心
public class EurekaApplication7001 {
	public static void main(String[] args) {
		SpringApplication.run(EurekaApplication7001.class,args);
	}
}

5.启动测试啦

业务模块注册到eureka中来

1.8001提供者注册到eureka
1)pom引入依赖:注意是client!

      <!--eureka-client-->
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
      </dependency>

2)yml添加eureka配置

eureka:
  client:
    register-with-eureka: true
    fetchRegistry: true
    service-url:
      defaultZone: http://localhost:7001/eureka

3)主启动类添加注解:@EnableEurekaClient

2.80消费者注册到eureka 同上
yml记得加上服务名称

springcloud学习系列目录

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值