I am using @PropertySource and PropertySourcesPlaceholderConfigurer to load my properties file:
@Configuration
@PropertySource("classpath:app.properties")
class MyApp {
@Bean
public PropertySourcesPlaceholderConfigurer PropertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
In app.properties, I would like to have:
database.dataSource.url=jdbc:postgresql://localhost:${db-port:5432}/mydb
Here, the port of the database is either resolved from the property db-port, or defaulted to 5432.
This would allow me to spawn my application with the -Ddb-port=9876 flag if necessary. If this flag is not set, the default port as written in app.properties should be taken.