1、使用nacos配置中心,需要将配置文件名称改为bootstrap.yml,否则会报:
Could not resolve placeholder 'info.name' in value "${info.name}"
2、2021后的spring cloud版本需要添加spring-cloud-starter-bootstrap依赖,否则会报:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
java
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
3、nacos配置
java
spring:
cloud:
nacos:
discovery:
server-addr: http://127.0.0.1:8848 # nacos注册地址
group: xge
namespace: 3ecaa9c7-8eff-4a39-995f-cc7fafe649 # 对应nacos的命名空间id
config:
server-addr: http://127.0.0.1:8848 # nacos注册地址
group: xge
namespace: 3ecaa9c7-8eff-4a39-995f-cc7fafe649 # 对应nacos的命名空间id
prefix: project-config
file-extension: yaml