Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

propertiesfactorybean vs propertyplaceholderconfigurer spring?

Tags:

java

spring

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!

like image 527
user755806 Avatar asked Dec 03 '13 14:12

user755806


People also ask

What can I use instead of PropertyPlaceholderConfigurer?

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.

What is the use of PropertyPlaceholderConfigurer in spring?

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.

How do you use PropertyPlaceholderConfigurer?

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.


1 Answers

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.

like image 153
M. Deinum Avatar answered Oct 12 '22 12:10

M. Deinum