使用com.alibaba.boot配置nacos,一定要在bootstrap.yml内配置nacos的相关配置,而不是application.yml
sprinboot整合nacos官网,例如pom的依赖是(注意:需要用上nacos的账号密码必须需要nacos-config-spring-boot-starter版本是0.2.6以上,使用nacos-config-spring-boot-starter匹配spring-boot-starter-parent版本2.6以下,如果使用2.6以上选择com.alibaba.cloud)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.8</version>
<relativePath/>
</parent>
...
...
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.3</version>
</dependency>
yml配置(nacos-config-spring-boot-starter)
nacos:
config:
server-addr: 192.168.11.47:18848
bootstrap:
enable: true
type: yaml
namespace: 038b3312-914b-4fbd-a12e-522c593f2b82