0

我正在使用@PropertySourcePropertySourcesPlaceholderConfigurer加载我的属性文件:

@Configuration
@PropertySource("classpath:app.properties")
class MyApp {
    @Bean
    public PropertySourcesPlaceholderConfigurer PropertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}

app.properties中,我想拥有:

database.dataSource.url=jdbc:postgresql://localhost:${db-port:5432}/mydb

在这里,数据库的端口要么从属性解析db-port,要么默认为 5432。

-Ddb-port=9876这将允许我在必要时使用该标志生成我的应用程序。如果未设置此标志,app.properties则应采用写入的默认端口。

4

1 回答 1