使用apachecommons配置基于活动概要文件的java加载属性文件

wz1wpwve  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(115)

我尝试使用apachecommons配置加载属性文件,因为我希望在属性文件中使用变量。这是预期的工作,但我也想apachecommons读取活动配置文件的属性文件,我不太清楚如何做。
我有一个常规的application.properties文件和几个application-env.properties文件,它们的属性类似于目标主机。我还有一个endpoints.properties文件,它将使用application-env.properties文件中的变量来确定url。
application-env.properties文件示例

hostname.1=https://url1.com
hostname.2=https://url2.com

endpoints.properties文件示例

user = ${hostname.1}/user
pet = ${hostname.2}/pet

目标是我可以在application-env.properties文件中添加几个主机名,并根据需要调整endpoints文件以使用正确的主机名
目前,我正在像这样读取endpoints.properties文件

Configurations configurations = new Configurations();
compositeConfiguration = new CompositeConfiguration();

PropertiesConfiguration propertiesConfiguration = configurations.properties(new File("endpoints.properties"));
compositeConfiguration.addConfiguration(propertiesConfiguration);

任何帮助都将不胜感激!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题