# bs-config-files **Repository Path**: SpringCloudTestGroup/bs-config-files ## Basic Information - **Project Name**: bs-config-files - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-11-26 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # bs-config-files #### 项目介绍 配制中心仓库-提供各项目不同环境的配制文件 #### 软件架构 ``` 1 Spring Boot 配置优先级顺序 配置属性加载的顺序如下: 1、开发者工具 `Devtools` 全局配置参数; 2、单元测试上的 `@TestPropertySource` 注解指定的参数; 3、单元测试上的 `@SpringBootTest` 注解指定的参数; 4、命令行指定的参数,如 `java -jar springboot.jar --name="Java技术栈"`; 5、命令行中的 `SPRING_APPLICATION_JSONJSON` 指定参数, 如 `java -Dspring.application.json='{"name":"Java技术栈"}' -jar springboot.jar` 6、`ServletConfig` 初始化参数; 7、`ServletContext` 初始化参数; 8、JNDI参数(如 `java:comp/env/spring.application.json`); 9、Java系统参数(来源:`System.getProperties()`); 10、操作系统环境变量参数; 11、`RandomValuePropertySource` 随机数,仅匹配:`ramdom.*`; 12、JAR包外面的配置文件参数(`application-{profile}.properties(YAML)`) 13、JAR包里面的配置文件参数(`application-{profile}.properties(YAML)`) 14、JAR包外面的配置文件参数(`application.properties(YAML)`) 15、JAR包里面的配置文件参数(`application.properties(YAML)`) 16、`@Configuration`配置文件上 `@PropertySource` 注解加载的参数; 17、默认参数(通过 `SpringApplication.setDefaultProperties` 指定); 数字小的优先级越高,即数字小的会覆盖数字大的参数值,我们来实践下,验证以上配置参数的加载顺序。 ``` #### 使用说明 1. 一般格式: ``` / {应用} / {轮廓} [/ {标号}] /{application}-{profile}.yml /{label}/{application}-{profile}.yml /{application}-{profile}.properties /{label}/{application}-{profile}.properties --------------------- name:就是你在远程仓库的yml文件名 profile:激活的剖面,比如spring.profiles.active = dev label:git资源的label 默认是master ``` 2. 配制中心服务器-加载配制仓库数据 1. 参考:[bs-server-config](https://gitee.com/SpringCloudTestGroup/bs-server-config) 2. @RefreshScope 客户接收刷新 ``` eg: @RefreshScope`客户接收刷新标记并非主动刷新` @RestController public class MyController { @Value("${foo}") String foo; @RequestMapping("/foo") public String hi(){ return foo; } } ``` 3. 手动刷新 手动刷新eg: http://localhost:80/refresh post 参考:[spring boot 配置动态刷新 - 剑握在手 - 博客园](https://www.cnblogs.com/flying607/p/8459397.html) 4. springCloud bus 消息总线刷新默认 2.0之前 /bus/refresh eg1:http://localhost:80/bus/refresh/ [SpringCloud之消息总线Spring Cloud Bus实例](https://blog.csdn.net/smartdt/article/details/79073765) eg2 2.0之后 刷新所有关联的 url:http://localhost:80/actuator/bus-refresh/ 只刷新本机 http://localhost:80/actuator/refresh ``` yml添加配制项 management: endpoints: web: exposure: #暴露bus-refresh节点,通过此节点刷新配置 include: '*'`也可以是bus-refresh` 或 management.endpoints.web.exposure.include= bus-refresh ``` 参考:[SpringCloud(十四)springCloud bus 消息总线刷新配置](https://blog.csdn.net/u012326462/article/details/80700347) 参考:[系统bus通知刷新:](https://www.cnblogs.com/cralor/p/9239976.html) #### 参考文献 [Spring Boot 配置优先级顺序 - 沧海一滴 - 博客园](https://www.cnblogs.com/softidea/p/5759180.html) [详解Spring Boot 配置加载顺序及属性加载顺序_java_脚本之家](https://www.jb51.net/article/146324.htm) [spring boot 配置动态刷新 - 剑握在手 - 博客园](https://www.cnblogs.com/flying607/p/8459397.html)