spring has two ways to load property files using either propertiesfactorybean or propertyplaceholderconfigurer.
Could u please explain the difference between them and when to use what?
Thanks!
Just use: final var configurer = new PropertySourcesPlaceholderConfigurer(); configurer. setProperties(properties); Side note: It even works as a replacement for configuring properties over the XML configuration.
Class PropertyPlaceholderConfigurer. A property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions.
To use PropertyPlaceholderConfigurer using annotation, we will create a static bean of it in java configuration class. To externalize the properties we will use PropertyPlaceholderConfigurer with @PropertySource and @Value . @PropertySource: It loads property file.
PropertiesFactoryBean
is a FactoryBean
implementation which reads a properties file and exposes that as an Properties
object in the applicationcontext.
PropertyPlaceHolderConfigurer
is a BeanFactoryPostProcessor
implementation that reads a property file and uses that property file to replace placeholder variables (${somename}) with actual values. The read properties aren't available as a Properties
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With