網站首頁 編程語言 正文
目錄
一、場景:
二、問題分析:
1、在服務啟動時,我注意到:
2、查看該服務的bootstrap.yml:
4、進入Config類,發現他有多個構造方法,懷疑問題出現在這里
5、注意到
三、解決問題
一、場景:
使用@RefreshScope注解,服務啟動后,在nacos配置中心,修改shared-configs下的配置文件mysql.yml,數據源無法實時更新
二、問題分析:
1、在服務啟動時,我注意到:
?nacos針對該服務只監聽了以上3個配置文件,而我的mysql.yml并沒有被監聽
2、查看該服務的bootstrap.yml:
cloud:
nacos:
config:
server-addr: localhost:8848
namespace: test
group: DEFAULT_GROUP
prefix: res-foods #res-foods-test.yml
file-extension: yml
username: nacos
password: nacos
shared-configs:
- mysql.yml
?
3、嘗試進入shared-configs發現調用了這個方法
public void setSharedConfigs(List<NacosConfigProperties.Config> sharedConfigs) {
this.sharedConfigs = sharedConfigs;
}
?
4、進入Config類,發現他有多個構造方法,懷疑問題出現在這里
public static class Config {
private String dataId;
private String group;
private boolean refresh;
public Config() {
this.group = "DEFAULT_GROUP";
this.refresh = false;
}
public Config(String dataId) {
this.group = "DEFAULT_GROUP";
this.refresh = false;
this.dataId = dataId;
}
public Config(String dataId, String group) {
this(dataId);
this.group = group;
}
public Config(String dataId, boolean refresh) {
this(dataId);
this.refresh = refresh;
}
public Config(String dataId, String group, boolean refresh) {
this(dataId, group);
this.refresh = refresh;
}
之前我直接寫
shared-configs:
- mysql.yml
調用了
public Config(String dataId) {
this.group = "DEFAULT_GROUP";
this.refresh = false;
this.dataId = dataId;
}
5、注意到
this.refresh = false;
于是找到問題所在,只需要在yml構造時調用其他的構造,即可
三、解決問題
shared-configs:
- {dataId: mysql.yml,refresh: true}
解決
原文鏈接:https://blog.csdn.net/qq_59384418/article/details/130179264
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-04-12 Oracle同步數據到kafka的方法_oracle
- 2022-11-04 詳解C++?指針與二維數組名_C 語言
- 2023-10-18 下載文件時前端重命名的實現方法將url地址轉化為文件實現重命名
- 2022-12-22 Python?Flask框架實現Proteus仿真Arduino與網頁數據交互_python
- 2022-06-11 sql?server查詢語句阻塞優化性能_MsSql
- 2022-04-10 詳解Unity日志打印工具功能_C#教程
- 2022-11-13 python學習之whl文件解釋與安裝詳解_python
- 2022-05-17 springboot打包為jar
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支