gpt4 book ai didi

Spring 上下文 :property-placeholder ignore resources not found

转载 作者:行者123 更新时间:2023-12-03 19:48:32 24 4
gpt4 key购买 nike

我想要一些资源,但如果缺少其他资源,则忽略其他资源......如何做到这一点?正如我所见,我只能做

<context:property-placeholder
ignore-resource-not-found="true"
location="required.properties, not-required-override.properties" />

这会影响那里提到的每个配置。

//编辑
这是一个工作示例
<bean id="requiredProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:database.properties</value>
<value>classpath:storage.properties</value>
<value>classpath:log4j.properties</value>
<value>classpath:mailing.properties</value>
</list>
</property>
</bean>

<context:property-placeholder
properties-ref="requiredProperties" ignore-resource-not-found="true"
location="file:\${user.dir}/config/cvnizer.properties" />

最佳答案

添加 PropertiesFactoryBean所需依赖项的元素,只需将属性连接到 <context:property-placeholder /> .

<bean id="requiredProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations" value="classpath:file1.properties,classpath:file2.properties" />
</bean>

<context:property-placeholder properties-ref="requiredProperties" ignore-resource-not-found="true" location="not-required-override.properties" />

这些属性将在运行时合并,因此您仍然可以在读取属性文件时进行覆盖。

关于 Spring 上下文 :property-placeholder ignore resources not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18694781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com