簡體   English   中英

Spring 將一個目錄中的所有配置文件導入另一個配置文件,而不顯式指定配置文件/文件名

[英]Spring import all configuration files in a directory into another configuration file without specifying the profiles / filenames explicitly

有沒有一種方法可以導入目錄中的所有配置文件,而不必一一明確指定它們的配置文件/文件名?

我想過使用spring.config.import但它似乎不支持指定目錄或模式來動態導入目錄中包含的任何配置文件。

例如:

我在config/目錄中有主配置application.yml和子配置,其中包含application-test1.ymlapplication-testN.yml等。 我想自動加載目錄下的所有配置文件,而不在application.yml中明確指定它們。

我在下面嘗試了這些,但它們不起作用。

spring
    config
        import: classpath:config/

spring
    config
        file: file:config/*/

spring.config.location=classpath:/custom-config/

這應該從指定的文件夾加載配置。 根據不同的配置文件配置,只會導入活動配置文件配置,因此您需要確保加載的標准配置文件激活這些配置文件(例如,使用spring.profiles.include

更多參考資料:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM