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

  • 相关阅读:
    [CQOI2005]三角形面积并(计算几何+扫描线)
    第一天
    LA3026 周期 (kmp)
    HDU 1715 大菲波数 (java大数)
    根据身高重建队列(vector)
    K 连续位的最小翻转次数
    724. Find Pivot Index
    Two Sum
    c
    Most Powerful(状压DP水题)
  • 原文地址:https://www.cnblogs.com/idoljames/p/11482670.html
Copyright © 2011-2022 走看看