一、加pom文件
<!-- Nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency>
nacos版本号如下:
<dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.2.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
二、bootstrap.yml中加nacos相关配置
spring: cloud: nacos: username: nacos password: nacos discovery: server-addr: http://192.168.111.90:31848 namespace: demo config: server-addr: http://192.168.111.90:31848 #配置中心的命名空间id namespace: demo #配置分组,默认没有也可以 group: DEFAULT_GROUP #配置文件后缀,用于拼接配置配置文件名称,目前只支持yml和properties file-extension: yml #配置自动刷新 refresh-enabled: true #配置文件的前缀,默认是application.name的值,如果配了prefix,就取prefix的值 prefix: ${spring.application.name}-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} # 配置编码 encode: UTF-8
# 共享配置 shared-configs: - data-id: common-datasource.yml refresh: true
标签:集成,springboot,spring,配置,nacos,alibaba,yml,cloud From: https://www.cnblogs.com/nuomm/p/17831077.html