1、增加依赖
<!--配置管理的依赖 -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId><version>2.1.0.RELEASE</version>
</dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId><version>4.1.4</version>
</dependency>
2、创建bootstrap.yaml文件
spring:application:name: user-serviceprofiles:active: dev
# 数据库配置迁移到了nacos
# datasource:
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/springcloud
# username: root
# password: 123456cloud:nacos:discovery:server-addr: 127.0.0.1:8848config:server-addr: 127.0.0.1:8848file-extension: yaml #文件后缀名
3、在nacos创建配置
4、重启服务成功
5、拉取nacos的多个配置文件
spring:application:name: user-service
# redis配置迁移到了nacos
# redis:
# host: 127.0.0.1
# port: 6379
# password:
# database: 0
server:port: 8083servlet:context-path: /user-service
# mybatis的配置迁移到了nacos
#mybatis-plus:
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志
logging:level:com.niuniu.user.feignclient.OrderClient: debug
将mybatis和redis的配置迁移到nacos,对应
bootstarp.yaml如下
spring:application:name: user-serviceprofiles:active: dev
# 数据库配置迁移到了nacos
# datasource:
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://localhost:3306/springcloud
# username: root
# password: 123456cloud:nacos:discovery:server-addr: 127.0.0.1:8848config:server-addr: 127.0.0.1:8848file-extension: yaml #文件后缀名shared-dataids: shared-redis.yaml,shared-mybatis.yaml
添加了shared-dataids: shared-redis.yaml,shared-mybatis.yaml
重启成功!