简体   繁体   中英

typesafe config: define global configurations to be used in “sub-configs ”

I have a large config file and I would like to avoid writing duplicates.

example:

shared_part: {
}

cof1 {
 . . . 
 subconf {
   shared: shared_part
 }
}

cof2 {
 . . . 
 subconf {
   shared: shared_part
 }
}

I tried to import the shared_par by simply writing it as it is and by ${shared_part} but none worked.

how would be the correct way to do it?

Firstly, I would recommend against big config files if the config blocks are meant to be used in different contexts, as I suppose your conf1 and conf2 do.

Define all your common properties in a sharedPart.conf (the naming is for the sake of your example), and the others in conf1.conf and conf2.conf . Afterwards, in order to use the common properties within the last two files, add the following to the head of the files:

include "sharedPart.conf"

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