3、撸一撸Spring Cloud - 创建Config配置中心

创建Config配置中心

本文需要对IDEA有一定的了解,清楚IDEA中项目与文件的创建,后续迭代补充基础知识

前期准备

  • 通过IDEA创建module dsz-config
  • 依赖项目dsz-root,dsz-eureka

Spring Cloud版本选型

  • Greenwich SR2
  • Spring Boot 2.1.6.RELEASE
  • Spring 5.1.8.RELEASE
  • jdk 1.8.0_172

最终展示pom.xml和项目结构

项目结构


项目结构

pom.xml



    
        dsz-root
        com.dsz.platform
        1.0-SNAPSHOT
    
    4.0.0

    dsz-config
    
    

        
            org.springframework.cloud
            spring-cloud-config-server
        

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

    


application.yml

server:
  port: 8888
spring:
  application:
    name: dsz-config
  cloud:
    config:
      server:
        git:
          ## 填写自己git仓库地址
          uri: https://github.com/***/dsz-root.git
          search-paths:
          - dsz-config
eureka:
  instance:
    hostname: 127.0.0.1
    ## 心跳间隔-5秒
    lease-renewal-interval-in-seconds: 5
    ## 没有心跳的淘汰时间-10秒
    lease-expiration-duration-in-seconds: 10
  client:
    ## 刷新本地缓存-5秒
    registry-fetch-interval-seconds: 5
    service-url:
      defaultZone: http://admin:admin@${eureka.instance.hostname}:8761/eureka/

com.dsz.base.config.ConfigApplication

package com.dsz.base.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }

}

下期预告《撸一撸Spring Cloud - 创建网关服务Gateway》

你可能感兴趣的:(3、撸一撸Spring Cloud - 创建Config配置中心)