如何在 PropertySource 中使用相对于用户家的路径

How to use path relative to user home in PropertySource

Spring 表达式在 PropertySource 注释中不起作用。

@PropertySource({ "classpath:application.properties",
        "#{systemProperties['user.home']}/.app.properties" })
@Configuration
public class Config {
@Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
        result.setOrder(0);
        return result;
    }
}

可以直接使用file:${user.home}加载用户home下的文件:

@PropertySource({ "classpath:application.properties", 
                  "file:${user.home}/.app.properties" })
@Configuration
public class Config {
}