2013-09-29 28 views
3

我需要包括一些配置文件到我的類型安全配置CONFIGS,像

include ${user.HOME}"/.app/db-test.conf" 

但是解析器抱怨:

com.typesafe.config.ConfigException$Parse: dev/application.conf: 47: include keyword is not followed by a quoted string, but by: '${'user.HOME'}' 
com.typesafe.config.ConfigException$Parse: dev/application.conf: 47: include keyword is not followed by a quoted string, but by: '${'user.HOME'}' 
    at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:329) 
    at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:325) 
    at com.typesafe.config.impl.Parser$ParseContext.parseInclude(Parser.java:574) 
    at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:624) 
    at com.typesafe.config.impl.Parser$ParseContext.parseValue(Parser.java:408) 
    at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:657) 
    at com.typesafe.config.impl.Parser$ParseContext.parse(Parser.java:832) 
    at com.typesafe.config.impl.Parser.parse(Parser.java:34) 

哪有我使用系統屬性/環境變量包括報表?

回答

1

你能在加載你的配置代碼中手動做到這一點?

Config baseConfig = ConfigFactory.load(); 
// Probably want error checking here. 
Config testConfig = ConfigFactory.parseFile(
    new File(System.getenv("HOME") + "/.app/db-test.conf")); 
// You may need to change your resolution order, depending on what you're doing in your 
// default config. 
testConfig.resolve(); 
Config finalConfig = baseConfig.withFallback(testConfig);