微服务实战 集中配置组件Config规避敏感信息泄露_config 敏感信息(3)

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

### 2、创建配置文件


新建config-server自身的配置文件application.yml



server:
port: 8005
spring:
application:
name: config-server
profiles:
active: native #使用本地文件
cloud:
config:
server:
native:
search-locations: classpath:/repo #本地配置仓库地址

git:

uri: https://gitee.com/xxxx/xxxxx.git

eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/


这里我们以使用本地配置仓库地址为例,`spring.profiles.active`设置为`native`,配置仓库路径为repo文件夹,所以我们在resources文件下创建repo文件夹,并创建新的一个configclient-dev.yml的文件,内容如下:



server:
port: 8007

eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
feign:
hystrix:
enabled: true
logging:
pattern:
console: ‘%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{15} - %msg%n’


### 3、新建启动类



/**
* @Author:公众号:程序员965
* @create 2022-07-05
**/
@EnableConfigServer //开启配置服务
@EnableEurekaClient
@SpringBootApplication
public class ConfitServerApplication {

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

}


注意增加`@EnableConfigServer`注解,表示这是个配置中心服务端。


### 4、创建配置中心客户端


服务端开发完成后,我们再新建一个客户端config-client项目,引入如下依赖:



org.springframework.cloud spring-cloud-starter-config

与服务端不同的是,客户端的配置文件我们创建bootstrap.yml文件



spring:
cloud:
config:
name: configclient
profile: dev
label: master
discovery:
enabled: true
service‐id: config-server

eureka:
client:
service‐url:
defaultZone: http://localhost:8001/eureka/


注意`spring.cloud.config.name`与服务端中的文件名称对应,`spring.cloud.config.profile`与文件名`-`后面的环境代码对应,配置文件的命名规则是 `{application}/{profile}[/{label}]` 。




![img](https://img-blog.csdnimg.cn/img_convert/0e86493b868bb1ac16e6f1489d03bd49.png)
![img](https://img-blog.csdnimg.cn/img_convert/652366c3e21a7cddfdbeadb69f0261f6.png)

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**


**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

.csdn.net/topics/618545628)**


**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值