简体   繁体   中英

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

Is there a way to import all configuration files in a directory without having to explicitly specify their profiles / filenames one by one?

I thought of using spring.config.import but it doesn't seem to support specifying a directory or pattern to dynamically import whatever configuration files are contained within the directory.

For example:

I have the main config application.yml and children config in the config/ directory, which contains application-test1.yml , application-testN.yml and so on. I want to automatically load all the config files under the directory without specifying them explicitly in application.yml .

I tried these below, but they don't work.

spring
    config
        import: classpath:config/

spring
    config
        file: file:config/*/

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

This should load the configuration from the specified folder. As per the different profiles configurations, only active profiles configuration would be imported, so you need to make sure that the standard configuration file that gets loaded activates these profiles (eg. using spring.profiles.include )

Further references:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM