zoukankan      html  css  js  c++  java
  • Eureka【入门】

    • 说明
      • SpringBoot版本 2.1.7.RELEASE
      • SpringCloud版本 Greenwich.SR2
    1. 创建eureka server工程

      1. 加入pom依赖
        <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
                </dependency>
            </dependencies>
        
            <dependencyManagement>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.cloud</groupId>
                        <artifactId>spring-cloud-dependencies</artifactId>
                        <version>Greenwich.SR2</version>
                        <type>pom</type>
                        <scope>import</scope>
                    </dependency>
                </dependencies>
            </dependencyManagement>  
      2. 启动类添加@EnableEurekaServer注解
        @EnableEurekaServer
        @SpringBootApplication
        public class EurekaApplication {
        
            public static void main(String[] args) {
                SpringApplication.run(EurekaApplication.class, args);
            }
        
        }
      3. application.yml文件中添加配置
        server:
          port: 8761
        
        
        spring:
          application:
            name: servers-register
        
        
        eureka:
          instance:
            hostname: localhost
          client:
            register-with-eureka: false
            fetch-registry: false
            service-url:
              defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
          server:
            wait-time-in-ms-when-sync-empty: 0
            enable-self-preservation: false

        注意:这里是单机版配置

    2. 创建eureka client工程

      1. 加入pom依赖
        <dependencies>
                <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</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
            </dependencies>
        
            <dependencyManagement>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.cloud</groupId>
                        <artifactId>spring-cloud-dependencies</artifactId>
                        <version>Greenwich.SR2</version>
                        <type>pom</type>
                        <scope>import</scope>
                    </dependency>
                </dependencies>
            </dependencyManagement>
      2. 启动类添加@EnableDiscoveryClient注解
        @EnableDiscoveryClient
        @SpringBootApplication
        public class UserServerApplication {
        
            public static void main(String[] args) {
                SpringApplication.run(UserServerApplication.class, args);
            }
        
        }
      3. application.yml添加配置
        server:
          port: 8081
        
        eureka: client: service
        -url: defaultZone: 'http://localhost:8761/eureka/'
        spring: application: name: user
        -server

        注意:这里的spring.application.name服务自定义名称,如果不定义的话,在eureka server的界面中展示的是UNKNOWN

    3. 启动server和client项目,访问localhost:8761

      提示:这里的USER-SERVER名称就是user-client工程配置文件中的 spring.application.name

  • 相关阅读:
    jQuery性能优化
    Google Chrome 浏览器 错误 312 (net::ERR_UNSAFE_PORT):未知错误。
    C#简单数字验证码解析
    折半查找
    平均分配算法之倒序贪婪
    字符串相似度算法(编辑距离算法 Levenshtein Distance)
    c# 冒泡排序算法中三种前后值交换算法效率测试
    二叉树的遍历
    C#使用Tesseract OCR 解析验证码
    页面瘦身之压缩viewState和保存viewState到服务器
  • 原文地址:https://www.cnblogs.com/idoljames/p/11482670.html
Copyright © 2011-2022 走看看