# hw **Repository Path**: leslie_gwb/hw ## Basic Information - **Project Name**: hw - **Description**: springcloud实践 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-04-13 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## nacos 配置中心 ### 顶层pom com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config ### NACOS控制台新建配置文件 * 参考配置 https://www.jianshu.com/p/3750b7be331f ### 加载配置文件 * springboot load file order bootstrap.properties -> bootstrap.yml -> application.properties -> application.yml ,其中 bootstrap.properties 配置为最高优先级 * 项目中新建资源文件 bootstrap.yml(开发默认关闭配置中心 加载本地application.yml) spring: profiles: #环境指定 active: dev cloud: nacos: config: namespace: d30e23fd-b25e-48df-b419-e7544e94b9a3 group: name1 file-extension: yml server-addr: localhost:8848 name: dd1 enabled: false * 配置测测试环境 新建bootstrap-test.yml spring: cloud: nacos: config: namespace: 8a5f0a7b-b1da-4291-8553-76d8390592a6 group: testGroup file-extension: yml server-addr: localhost:8848 name: testEnv #开启配置中心 enabled: true ### 对应加载配置的类 如果需要更新属性key 需注解@RefreshScope @RestController @RequestMapping("/config") @RefreshScope public class ConfigController { @Value("${useLocalCache:false}") private boolean useLocalCache; @Value("${my.test.name}") private String name; @RequestMapping("/get") public boolean get() { return useLocalCache; } @RequestMapping("/hi") public String hi() { return "hi " +name; } }