简体   繁体   中英

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

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

From PropertySourcesPlaceholderConfigurer docs

PropertySourcesPlaceholderConfigurer is more flexible and interacts with Environment and PropertySource. It can be local properties or system properties or environment variables.

Specialization of PlaceholderConfigurerSupport that resolves ${...} placeholders within bean definition property values and @Value annotations against the current Spring Environment and its set of PropertySources .

PropertyPlaceholderConfigurer

We use PropertyPlaceholderConfigurer when we need to load some property files whose properties are used in applicationcontext.xml of spring. We can use the properties directly using JSTL expressions.

@PropertySource

This annotation contributes properties to the active Spring environment .

context:property-placeholder

Registers a component which can resolve placeholders of form ${propertyname} in bean definitions. It is intelligent enough to know that it needs to look not just at the properties registered through its location attribute but also to look at the properties available in the current active environment (which properties have been added in through the @PropertySource annotations).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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