首页 > 编程语言 > 详细

Spring Cloud Config 配置中心

时间:2019-10-27 09:14:13      阅读:101      评论:0      收藏:0      [点我收藏+]
Spring Cloud Config 配置中心
 
1、引入依赖
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
</dependencies>
 
2、aplication.yml 配置
server:
  port: 8089
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:8081/eureka
    ##是否需要将自己注册到注册中心
    register-with-eureka: true
    ##是否需要检索服务信息
    fetch-registry: true
spring:
  application:
    name: wms-config
  cloud:
    config:
      label: master
      server:
        git:
          uri: https://gitee.com/shuchang14/wms-config.git
          #搜索配置文件目录
          search-paths:
          - zuul
          username: XXXXXXXX
          password: ********
 
3、ConfigApplication启动类加注解
/**
* @EnableEurekaClient 启用eureka 客户端
* @EnableConfigServer 启用config 服务端
*/
@EnableEurekaClient
@EnableConfigServer
@SpringBootApplication
public class ConfigApplication {
 
    public static void main(String[] args){
        SpringApplication.run(ConfigApplication.class,args);
    }
}
 
4、ConfigServer启动后,浏览器请求Git上面的文件(这样才把文件加载到ConfigServer内存中),之后ConfigClient会从ConfigServer内存中获取相应的配置信息。
技术分享图片技术分享图片
5、git 仓库上的文件命名规范
    [服务名称]-[环境].yml
    [服务名称]-[环境].properties
   例如:zuul网关服务的服务名称为:zuul  即:aplication.name=zuul ,启动sit环境。 其对应的git 上的配置文件名称为:zuul-sit.yml
 

Spring Cloud Config 配置中心

原文:https://www.cnblogs.com/ycsc/p/11746428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!