如何解决使用 Apache Commons 配置基于活动配置文件加载属性文件
我正在尝试使用 Apache Commons Configuration 加载属性文件,因为我想在我的属性文件中使用变量。这按预期工作,但我也希望 Apache Commons 读取活动配置文件的属性文件,但我不太确定该怎么做。
我有一个常规的 application.properties 文件和几个具有目标主机等属性的 application-ENV.properties 文件。我还有一个 endpoints.properties 文件,它将使用 application-ENV.properties 文件中的变量来确定 url。
应用程序-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.properties 文件
Configurations configurations = new Configurations();
compositeConfiguration = new CompositeConfiguration();
PropertiesConfiguration propertiesConfiguration = configurations.properties(new File("endpoints.properties"));
compositeConfiguration.addConfiguration(propertiesConfiguration);
任何帮助将不胜感激!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。