• spring cloud:eureka


    Eureka-server

    1.file-->new--> spring starter project  : eureka-server

    2.添加依赖

      <!-- eureka-server -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
                <version>2.1.1.RELEASE</version>
            </dependency>
            <!-- eureka-server -->

    3.修改port:新建application.yml:

    server:
      port: 8761
    
    eureka:
      instance:
        hostname: localhost
      client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

    4. EurekaServerApplication添加注解@EnableEurekaServer

    package com.smile.eurekaserver;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    
    @SpringBootApplication
    @EnableEurekaServer
    public class EurekaServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaServerApplication.class, args);
        }
    
    }

    5访问:http://localhost:8761/ 

     Eureka-client

    1.file-->new--> spring starter project  : eureka-client

    2.添加依赖

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.5.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    <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>

    3.修改port:新建application.yml:

    server:
      port: 8001
    
    eureka:
      client:
    #    registerWithEureka: false
    #    fetchRegistry: false
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    
    spring:
      application:
        name: eureka-client

    4. EurekaClientApplication添加注解@@EnableEurekaClient

    package com.smile;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    
    @SpringBootApplication
    @EnableEurekaClient
    public class EurekaClientApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaClientApplication.class, args);
        }
    
    }

    5启动项目,访问:http://localhost:8761/  这里已经多了一个instance

  • 相关阅读:
    Cypher 语句实战
    springboot2.0-统一处理返回结果和异常情况
    IM系统的MQ消息中间件选型:Kafka还是RabbitMQ?
    Dripicons – 精美的扁平风格的免费矢量图标字体
    实用手册:130+ 提高开发效率的 vim 常用命令
    RulersGuides.js – 网站中实现 Photoshop 标尺效果
    分享27款最佳的复古风格 WordPress 主题
    Web 开发人员必备的12款 Chrome 扩展程序
    酷站欣赏:20个精美的国外扁平化网页设计作品
    编码神器——Sublime Text 包管理工具及扩展大全
  • 原文地址:https://www.cnblogs.com/alittlesmile/p/10883112.html
Copyright © 2020-2023  润新知