java - 从配置文件的活动列表中动态加载属性值并在配置 XML 文件中设置值
问题描述
我有一个包含批处理配置的弹簧浴应用程序。我想根据活动配置文件列表的环境变量参数动态加载配置文件。一旦我得到值,我必须在批处理配置 xml 文件中设置变量。它工作正常,而活动配置文件值是单一的,如果我喜欢它,它工作正常
<context:property-placeholder location="classpath:application-${spring.active.profile}.properties" />
但我有一个活动配置文件列表,例如:-Dspring.active.profile=dev,localproperties,mycerts。我想获取活动配置文件的第一个值并加载属性文件并加载 application-dev.properties。我尝试了以下方式,但将整个字符串作为配置文件值。我如何加载活动配置文件的第一个值/。
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<util:list>
<value>classpath:application-${spring.profiles.active}.properties</value>
</util:list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
我怎么能做到这一点?
解决方案
我有一个活动配置文件列表,例如:-Dspring.active.profile=dev,localproperties,mycerts。我想获取活动配置文件的第一个值
您可以为此使用 SpEL 表达式,例如:
<context:property-placeholder
location="classpath:application-#{environment.getActiveProfiles()[0]}.properties" />
请注意,该属性已命名spring.profiles.active
,而不是spring.active.profile
.
推荐阅读
- python - 我安装了一个名为 Discord 的模块,在使用“import discord”时出现错误:“ModuleNotFoundError: No module named 'discord'”
- mysql - Is SHOW statement in SQL?
- c# - How can I hide browser of Selenium IEDriver?
- javascript - React - 从根 app.js 文件导出不起作用
- azure - 分布式交换操作
- ios - 由于缺少图标,Xcode Build 未提交
- linux - 在 Linux 中创建、锁定和解锁目录
- javascript - 从 json 列表中获取特定值 在邮递员测试中使用 javascript
- vb.net - VB.net 将 TextBox 的 NULL 值转换为 Integer
- php - 设置和检索会话值 wordpress