Spring Cloud Config为服务端和客户端

Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持,配置服务中心采用Git的方式存储配置文件,

因此我们很容易部署修改,有助于对环境配置进行版本管理。

一、配置中心

在根目录spring_cloud中创建Maven Moudle模块:config-server

pom.xml

 
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  3. <parent>

  4. <artifactId>spring-cloud</artifactId>

  5. <groupId>com.sam</groupId>

  6. <version>0.0.1</version>

  7. </parent>

  8. <modelVersion>4.0.0</modelVersion>

  9.  
  10. <artifactId>config-server</artifactId>

  11.  
  12. <dependencies>

  13. <dependency>

  14. <groupId>org.springframework.cloud</groupId>

  15. <artifactId>spring-cloud-config-server</artifactId>

  16. </dependency>

  17.  
  18. </dependencies>

  19.  
  20. </project>

创建消费者服务启动类:ConfigApplication

 
  1. package com.sam.config.server;

  2.  
  3. import org.springframework.boot.SpringApplication;

  4. import org.springframework.boot.autoconfigure.SpringBootApplication;

  5. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

  6. import org.springframework.cloud.config.server.EnableConfigServer;

  7.  
  8. /**

  9. * @ClassName: ConfigApplication

  10. * @Description: 配置中心服务

  11. * @author sam

  12. * @date 2018年8月10日 下午3:49:01

  13. */

  14. @SpringBootApplication

  15. @EnableConfigServer

  16. @EnableDiscoveryClient

  17. public class ConfigApplication {

  18.  
  19. public static void main(String[] args) {

  20. SpringApplication.run(ConfigApplication.class, args);

  21. }

  22. }

创建配置文件:application.yml

 
  1. server:

  2. port: 8030

  3.  
  4. eureka:

  5. client:

  6. serviceUrl:

  7. defaultZone: http://localhost:8010/eureka/ #eureka服务注册地址

  8.  
  9. # git管理配置

  10. spring:

  11. cloud:

  12. config:

  13. server:

  14. git:

  15. uri: https://github.com/vtopqx/config/ #git仓库地址

  16. searchPaths: demo* #搜索路径

  17. # username: username

  18. # password: password

  19. application:

  20. name: config-server

  21.  
  22. management:

  23. security:

  24. enabled: false #是否开启actuator安全认证

  25.  
  26.  

在配置的git仓库下新建一个demo1的文件夹,在里面创建一个叫client-a-dev.properties的配置文件
文件中随便加上两个配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值