springcloud2020 版本开始 Bootstrap默认是禁用的,所以加上bootstrap就行了
我这里的spring-cloud版本为2021.0.5,同样加上就行了
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-bootstrap</artifactId>
- </dependency>
集成nacos作为配置中心的完整配置
- <dependency>
- <groupId>com.alibaba.cloud</groupId>
- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
- </dependency>
-
- <!-- 若报错 No spring.config.import set 加bootstrap 依赖 -->
- <!--springcloud2020 版本开始 Bootstrap默认是禁用的-->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-bootstrap</artifactId>
- </dependency>
bootstrap.yml
- spring:
- cloud:
- nacos:
- config:
- server-addr: 127.0.0.1:8848
- file-extension: yaml
- application:
- # 服务名称,不要用下划线,更不要用特殊字符
- name: content-center
- profiles:
- active: dev
Data ID content-center-dev.yaml
- your:
- configuration: itmuch