Вы можете использовать,
reference.conf
fs {
city = "Delhi"
number = 31
}
myconf.conf
conf {
city = ${fs.city}
number = ${fs.number}
cityNumberKey = ${conf.city}"_"${conf.number}
cityNumber = ${conf.cityNumberKey}
}
TypesafeConfigTest. java
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
public class TypesafeConfigTest {
public static void main(String[] args) {
Config refConfig = ConfigFactory.parseResources("reference.conf").resolve();
Config myConfConfig = ConfigFactory.parseResources("myconf.conf").withFallback(refConfig).resolve();
System.out.println("name: " + refConfig.getString("fs.city"));
System.out.println("title: " + refConfig.getString("fs.number"));
System.out.println("cityNumberKey: " + myConfConfig.getString("conf.cityNumberKey"));
System.out.println("cityNumber: " + myConfConfig.getString("conf.cityNumber"));
}
}
Редактировать 1:
Используя одну конфигурацию,
conf {
city = "Delhi"
number = 31
cityNumberKey = ${conf.city}"_"${conf.number}
cityNumber = ${conf.cityNumberKey}
}
TypesafeConfigExamples. java
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
public class TypesafeConfigExamples {
public static void main(String[] args) {
Config refConfig = ConfigFactory.parseResources("myconf.conf").resolve();
System.out.println("name: " + refConfig.getString("conf.city"));
System.out.println("title: " + refConfig.getString("conf.number"));
System.out.println("cityNumberKey: " + refConfig.getString("conf.cityNumberKey"));
System.out.println("cityNumber: " + refConfig.getString("conf.cityNumber"));
}
}