我正在使用@PropertySource
并PropertySourcesPlaceholderConfigurer
加载我的属性文件:
@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
则应采用写入的默认端口。