依赖
1 2 |
// https://mvnrepository.com/artifact/com.alibaba.boot/nacos-config-spring-boot-starter implementation group: 'com.alibaba.boot', name: 'nacos-config-spring-boot-starter', version: '0.2.12' |
配置文件 application.yml
1 2 3 4 5 |
nacos: config: server-addr: 127.0.0.1:8848 username: xxxx password: xxxxxx |
注解 @NacosPropertySource
1 2 3 4 5 6 7 8 9 10 |
@SpringBootApplication @MapperScan("com.w3cnet.xxx.repository") @NacosPropertySource(dataId = "xxx-prod.yml", autoRefreshed = true) public class XxxxApplication { public static void main(String[] args) { SpringApplication.run(XxxxApplication.class, args); } } |
注解 @NacosValue
1 2 |
@NacosValue(value = "${xxx.url}", autoRefreshed = true) private String xxxUrl; |
参考资料:https://nacos.io/zh-cn/docs/quick-start-spring-boot.html