【微服务架构 - 08 - Spring Cloud】08 分布式配置中心

pom.xml


添加 spring-cloud-config-server 依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>

Application


通过 @EnableConfigServer` 注解,开启配置服务功能

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

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

bootstrap.yml


增加 Config 相关配置,并设置端口号为:8888

spring:
  application:
    name: hello-spring-cloud-config
  cloud:
    config:
      label: master
      server:
        git:
          uri: https://github.com/***/spring-cloud-config
          search-paths: respo
          username:
          password:

server:
  port: 8888

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

相关配置说明,如下:

  • spring.cloud.config.label: 配置仓库的分支
  • spring.cloud.config.server.git.uri:配置 Git 仓库地址
  • spring.cloud.config.server.git.search-paths: 配置仓库路径(存放配置文件的目录)
  • spring.cloud.config.server.git.username: 访问 Git 仓库的账号
  • sping.cloud.config.server.git.password:访问 Git 仓库的密码

HTTP 请求地址和资源映射文件


  • http://ip:port/{application}/{profile}[/{label}]
  • http://ip:port/{application}-{profile}.yml
  • http://ip:port/{label}/{application}-{profile}.yml
  • http://ip:port/{application}-{profile}.properties
  • http://ip:port/{label}/{application}-{profile}.properties

猜你喜欢

转载自blog.csdn.net/qq_37581282/article/details/88098992