[英]Spring - Is it possible to resolve properties (such as environment variables) recursively in properties file?
I am using @PropertySource
and PropertySourcesPlaceholderConfigurer
to load my properties file: 我正在使用
@PropertySource
和PropertySourcesPlaceholderConfigurer
加载我的属性文件:
@Configuration
@PropertySource("classpath:app.properties")
class MyApp {
@Bean
public PropertySourcesPlaceholderConfigurer PropertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
In app.properties
, I would like to have: 我希望在
app.properties
中具有:
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. 在这里,数据库的端口从属性
db-port
解析,或者默认为5432。
This would allow me to spawn my application with the -Ddb-port=9876
flag if necessary. 如果需要的话,这将允许我使用
-Ddb-port=9876
标志生成应用程序。 If this flag is not set, the default port as written in app.properties
should be taken. 如果未设置此标志,则应采用
app.properties
编写的默认端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.