6

Spring expressions doesn't work inside the PropertySource annotation.

@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;
    }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49

1 Answers1

13

You can directly use file:${user.home} to load a file under user home:

@PropertySource({ "classpath:application.properties", 
                  "file:${user.home}/.app.properties" })
@Configuration
public class Config {
}
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525