欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SpringCloud:1章 Eureka服务注册与发现

程序员文章站 2022-05-09 10:28:17
新建Eureka模块配置yml文件```javaserver: port: 2001eureka: instance: hostname: localhost #eurake实例名 client: service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka register-with-eureka: false #表示不想注册中心注册自已....
  1. 新建Eureka模块
    SpringCloud:1章 Eureka服务注册与发现
  2. 配置yml文件
server:
  port: 2001
eureka:
  instance:
    hostname: localhost  #eurake实例名
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
    register-with-eureka: false #表示不想注册中心注册自已
    fetch-registy: false #表示不需要检索服务

3.启动类加上@EnableEurekaServer注解

@EnableEurekaServer
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

4.访问http://localhost:2001/ 出现如下画面则成功
SpringCloud:1章 Eureka服务注册与发现
5. 创建注册者模块
SpringCloud:1章 Eureka服务注册与发现
6. 配置yml文件

server:
  port: 2002

spring:
  application:
    name: clinet_1 #注册名字

eureka:
  client:
    service-url:
      defaultZone: http://localhost:2001/eureka

7.启动类加入注解@EnableEurekaClient

@EnableEurekaClient
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
  1. 检查依赖是否有这两个
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
  1. 访问http://localhost:2001 成功则出现
    SpringCloud:1章 Eureka服务注册与发现

本文地址:https://blog.csdn.net/weixin_42654295/article/details/107599449