既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
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}]` 。
当 Config Client 去访问 Config Server 时,`spring.cloud.config.name` 、`spring.cloud.config.profile` 以及 、`spring.cloud.config.label` 的值分别对应上面三个占位符,如果配置了`spring.cloud.config.name`,那么就取`spring.cloud.config.name`,如果没有配置就取 `spring.application.name`,通过灵活使用 `{application}` 、`{profile}` 、`{label}` 三个占位符,就可以来动态地控制 client 从 server 所访问的仓库!
然后编写客户端启动类:
/**
* @Author:公众号:程序员965
* @create 2022-07-05
**/
@EnableDiscoveryClient
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
### 5、验证
我们分别启动registry项目以及config-server,config-client两个服务,这时,就会发现,config-client服务拉取了config-server中对应的配置文件。



**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.youkuaiyun.com/topics/618545628)**
体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.youkuaiyun.com/topics/618545628)**