zoukankan      html  css  js  c++  java
  • spring cloud 注册与发现Eureka

    spring cloud 注册与发现

    在这里使用Eureka作为注册中心。

    一、eureka-server

    创建新的module:eureka-server

    1.1 引入eureka-server依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
    

    1.2 配置文件

    server.port=8761
    #eureka server
    eureka.instance.hostname=localhost
    #注册到eureka服务中心
    eureka.client.register-with-eureka=false
    #检索服务
    eureka.client.fetch-registry=false
    eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
    

    1.3 启动类

    启动类添加注解@EnableEurekaServer

    @EnableEurekaServer
    @SpringBootApplication
    public class EurekaServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaServerApplication.class, args);
        }
    
    }
    

    二、eureka-client

    创建新的module:eureka-client

    2.1 引入eureka-client坐标

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>
    

    2.2 配置文件

    #注册进eureka,默认true
    server.port=8001
    eureka.client.register-with-eureka=true
    #默认true
    eureka.client.fetch-registry=true
    eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
    
    spring.application.name=eureka-client
    

    2.3 启动类

    启动类添加注解@EnableEurekaClient

    @EnableEurekaClient
    @SpringBootApplication
    public class EurekaClientApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaClientApplication.class, args);
        }
    
    }
    

    三、查看注册中心

    访问eureka注册中心,可以查看已经注册到eureka的服务有哪些。

    3.1 运行

    依次启动eureka-server、eureka-client

    3.2访问

    访问http://localhost:8761

    在这里可以看到已经注册进来的实例都有哪些。

  • 相关阅读:
    http://gzbbs.soufun.com/2811007370~59~471/4372594_4372594.htm
    借dudu的地方招个标,寻找广州网站开发外包公司
    System.InvalidOperationException: 哈希表插入失败。加载因子太高。
    网络艺术品交易黑洞
    水润麻涌
    麻涌蕉林香飘四季
    web开发的浏览器(工具)插件
    很好很强大的六个SEO关键词分析工具
    (转载)library cache lock和library cache pin到底是什么
    (转载)library cache lock和library cache pin到底是什么(续)
  • 原文地址:https://www.cnblogs.com/Zzwena/p/12539706.html
Copyright © 2011-2022 走看看