spring cloud 配置中心 結合GIT , 可以運行時更新配置文件.發送指令讓應用重新讀取配置文件.
最近在測試服務器實現了一套,結果CPU 實用率暴增,使用docker compose啟動 restart always 多節點的服務一直重啟關閉重啟關閉.
日志文件記錄了一個異常: 國內國外搜了一遍都沒有解決
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration':
Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
直到有一個應用拋了一個端口被占用的異常后,才恍然大悟
原因如下,在當前配置文件中,application-test中的端口配置為:
#服務器參數配置
server:
port: 8060
max-threads: 2000
max-connections: 2000
一般情況下我們 docker cmd 或者 entrypoint 啟動應用
命令為:
java -jar app.jar --spring.profiles.active=test --server.port=8060
在沒有使用配置中心的時候,Spring 應用會根據命令行的參數的服務端口啟動.
但是使用了配置中心,應用啟動時去GIT 獲取配置文件的時候,會把命令行的參數覆蓋掉
解決辦法就是:注釋掉,或者不寫,反正也沒有必要寫
#服務器參數配置
server:
# port: 8060
max-threads: 2000
max-connections: 2000
還有注意配置文件編碼集,會引發無法讀取配置文件的問題.拋出以下異常
java.lang.IllegalStateException: Failed to load property source from location 'file:/tmp/config-repo-3518188927963973603/config/zuul-router-prod.yml'