SpringCloud2020整合Nacos-Bootstrap配置不生效的解决
在使用nacos-config读取nacos配置时。发现bootstrap.yml一直不生效。
翻看SpringCloud2020的官方文档,发现果然是springcloud2020的原因。
还是引入依赖解决问题
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
引入以上依赖。完美解决问题
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springcloud2021</artifactId>
<groupId>com.test.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloudalibaba-config-nacos-client3377</artifactId>
<dependencies>
<!-- nacos config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud alibaba nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- 引入自定义的api通用包,可以使用Payment支付Entity -->
<dependency>
<groupId>com.test.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- web组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
</project>
bootstrap.yml
server:
port: 3377
spring:
application:
name: nacos-config-client
cloud:
nacos:
discovery:
server-addr: localhost:8848 # Nacos 服务注册中心地址
namespace: 37dfc50e-2e13-4937-ab73-a1b80ad35db3
config:
server-addr: localhost:8848 # Nacos 作为配置中心地址
file-extension: yaml #指定yaml格式的配置 yml会报错,nacos识别yaml
# 加载配置才需要以下配置
namespace: 37dfc50e-2e13-4937-ab73-a1b80ad35db3
group: PROD_GROUP
############################################################################
# 官网文档 https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html
# ${spring.application.name}-${spring.profile.active}.${spring.cloud.nacos.config.file-extension}
# 以上匹配规则转换后 ===> nacos-config-client-dev.yaml
# 在nacos配置中心配置 http://localhost:8848/nacos
############################################################################
application.yml
spring:
profiles:
active: prod
# # active: test
## active: info