繁体   English   中英

通过@propertysource批注和使用PropertySourcesHolderConfigure bean在春季加载属性文件之间有什么区别?

[英]What is the difference between loading properties files in spring through @propertysource annotation and by using PropertySourcesHolderConfigure bean

我正在研究如何在Spring中访问属性文件,并且很困惑地发现<context:property-placeholder>PropertySourcesPlaceHoderConfigure@PropertySourcePropertyPlaceHolderConfigure之间的区别。

来自PropertySourcesPlaceholderConfigurer文档

PropertySourcesPlaceholderConfigurer更加灵活,并且可以与Environment和PropertySource进行交互。 它可以是局部属性或系统属性或环境变量。

PlaceholderConfigurerSupport特殊化,可针对当前的Spring Environment及其PropertySources解析bean定义属性值和@Value注释内的${...}占位符。

PropertyPlaceholderConfigurer

当需要加载一些属性文件的属性在spring的applicationcontext.xml中使用时,我们使用PropertyPlaceholderConfigurer。 我们可以直接使用JSTL表达式来使用属性。

@PropertySource

该注释为活动的Spring环境提供了属性。

上下文:属性占位符

注册一个组件,该组件可以在bean定义中解析形式$ {propertyname}的占位符。 知道自己不仅需要查看通过其location属性注册的属性,还需要查看当前活动环境中可用的属性(已通过@PropertySource批注添加了这些属性),已足够聪明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM