1. 程式人生 > >org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eu

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eu

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'