How to reference a system property within a user-defined .properties file?

后端 未结 3 759
别那么骄傲
别那么骄傲 2020-12-19 03:07

I want to define a property for a working directory(say work.dir=/home/username/working-directory), for my production .properties file, without hard-coding the

3条回答
  •  借酒劲吻你
    2020-12-19 03:33

    This feature is not available in java.util.Properties. But many libraries add variable substitution to properties.

    Here an example of what you are trying to do using OWNER API library (see paragraph "importing properties"):

    public interface SystemPropertiesExample extends Config {
        @DefaultValue("Welcome: ${user.name}")
        String welcomeString();
    
        @DefaultValue("${TMPDIR}/tempFile.tmp")
        File tempFile();
    }
    
    SystemPropertiesExample conf =
            ConfigFactory.create(SystemPropertiesExample.class, System.getProperties(), System.getenv());
    String welcome = conf.welcomeString();
    File temp = conf.tempFile();
    

提交回复
热议问题