1.看依赖是否正确
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.2</version>
</dependency>
2.配置yml
spring:
profiles:
active: dev
application:
name: nacos-test
cloud:
nacos:
config:
name: nacos-test-dev.yaml
server-addr: 192.168.1.15:8848
namespace: 75e0b9fd-4457-45d9-bc8a-94a8594bc9b6
group: DEFAULT_GROUP
file-extension: yaml
3.我遇到的问题:只有一级的可以读取到,二级的不行:
只能读取到@Value("${myConfig}")
读取不到@Value("${my.config}")
是因为我没有加file-extension: yaml
看下默认配置:
真相大白,一级目录符合properties格式,所以能读取到,二级及以上的不符合,所以读取不到