[英]How to initialize a set in a spring bean using value from .properties file
[英]How to set spring bean properties in a .properties resource file
是否可以通过.properties文件中的点表示法设置spring bean的属性。 例如,假设您已定义:
<bean name="myBean" class="MyBean" />
是否可以将myBean的MyBean.someProperty设置为属性文件中定义的值? 例如,通过此属性文件:
myBean.someProperty = aValue
我知道PropertyPlaceholderConfigurer,但我的要求与它支持的有些不同。
如果你的xml中有一个属性,你可以从属性文件中分配一个值
<property name="someProperty" value="${myBean.someProperty}" />
必须处理PropertyPlaceholderConfigurer
但我想,您想要覆盖您的属性,所以请查看PropertyOverrideConfigurer
的文档
<context:property-placeholder location="classpath:/application.properties" />
<property name="myProperty" value="${myProperty.key.of.properties}" />
Spring发行版中还提供了一个PropertyOverrideConfigurer
可以完全满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.