In xml configuration I can do the following:
<context:property-placeholder
location="file:${user.home}/.config}/api.properties"
ignore-resource-not-found="true"
system-properties-mode="OVERRIDE"/>
In java configuration I would do the following:
/**
* @return a {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer} so that placeholders are correctly populated
* @throws Exception exception if the file is not found or cannot be opened or read
*/
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws Exception {
PropertySourcesPlaceholderConfigurer propConfig = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new UrlResource[]
{new UrlResource("file:${user.home}/.config/api.properties")};
propConfig.setLocations(resources);
propConfig.setIgnoreResourceNotFound(true);
propConfig.setIgnoreUnresolvablePlaceholders(true);
return propConfig;
}
However this doesn't understand ${user.home}
Try ${sys:user.home}
to refer system property. For system environment use ${env:THE-ENV-VAR-NAME}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With