### 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行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**