springcloud-注册中心快速构建

1. 场景描述

springcloud提供了一整套可行的构建分布式系统的方案,使的企业/开发人员能够快速沟通分布式系统,今天快速构建下springcloud的注册中心Eureka。

2. 解决方案

2.1 springcloud介绍

COORDINATE ANYTHING: DISTRIBUTED SYSTEMS SIMPLIFIED

Building distributed systems doesn’t need to be complex and error-prone. Spring Cloud offers a simple and accessible programming model to the most common distributed system patterns, helping developers build resilient, reliable, and coordinated applications. Spring Cloud is built on top of Spring Boot, making it easy for developers to get started and become productive quickly.

springcloud-注册中心快速构建_第1张图片

2.2 项目构建

使用的idea终极版,springcloud项目本身就是springboot项目(springboot与springcloud的关系)。

首先在idea中创建项目:fil–>new–>project

springcloud-注册中心快速构建_第2张图片

两个默认next后选择组件

springcloud-注册中心快速构建_第3张图片

默认next->finish

2.3 配置文件pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.4.RELEASE
         
    
    com.spc
    eurekaserver
    0.0.1-SNAPSHOT
    eurekaserver
    Demo project for Spring Boot

    
        1.8
        Greenwich.SR1
    

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



2.4 application启动类

package com.spc.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);
    }

}

2.5 application.yml文件

spring:
  application:
    name: registry

server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    service-url:
      defaultZone: http://localhost:8761/eureka/

2.6 启动应用

springcloud-注册中心快速构建_第4张图片


I’m 「软件老王」,如果觉得还可以的话,关注下呗,后续更新秒知!欢迎讨论区、同名公众号留言交流!

你可能感兴趣的:(java,springcloud专栏)