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

    技术2022-07-11  86

    单机版注册中心

    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学习系列目录

    Processed: 0.012, SQL: 9