0

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.

Jessy56
  • 63
  • 1
  • 10
  • We currently do something similar via `ReplaceTokens`. You could likely do this the same way. This is somewhat similar to [this question](https://stackoverflow.com/questions/21247193/gradle-replace-token-in-a-file-during-build-process). – Mike Hill Oct 24 '17 at 22:11