很多csdn上文章说在springboot上加载数据源等信息必须要用bootstrap.yml,还要加载这些依赖
com.alibaba.cloud
spring-cloud-starter-alibaba-nacos-config
LATEST
加上nacos的官方文档不够详细,我一开始也以为只能通过springcloud的方式才能加载数据源,
实际上不需要,springboot也可以做到,就行了,这个官方文档藏得很深,要费劲才能找到
在 application.properties 中设置以下参数:
开启配置预加载功能
nacos.config.bootstrap.enable=true
主配置服务器地址
nacos.config.server-addr=192.168.16.104:8848
主配置 data-id
nacos.config.data-id=people
主配置 group-id
nacos.config.group=DEFAULT_GROUP
主配置 配置文件类型
nacos.config.type=properties
主配置 最大重试次数
nacos.config.max-retry=10
主配置 开启自动刷新
nacos.config.auto-refresh=true
主配置 重试时间
nacos.config.config-retry-time=2333
主配置 配置监听长轮询超时时间
nacos.config.config-long-poll-timeout=46000
主配置 开启注册监听器预加载配置服务(除非特殊业务需求,否则不推荐打开该参数)
nacos.config.enable-remote-sync-config=true
主配置 remote-first 设置
nacos.config.remote-first=true
支持日志级别的加载时机
nacos.config.bootstrap.log.enable=true
nacos 用户名密码
nacos.config.username=nacos
nacos.config.password=nacos
配置文件扩展 index越小,优先级越高,从0开始
nacos.config.ext-config[0].data-id=test
nacos.config.ext-config[0].group=DEFAULT_GROUP
nacos.config.ext-config[0].max-retry=10
nacos.config.ext-config[0].type=yaml
nacos.config.ext-config[0].auto-refresh=true
nacos.config.ext-config[0].config-retry-time=2333
nacos.config.ext-config[0].config-long-poll-timeout=46000
nacos.config.ext-config[0].enable-remote-sync-config=true