PropertyPlaceholderConfigurer usage

PropertiesFactoryBean is a FactoryBean implementation which reads a properties file and exposes that as a Properties object in the ApplicationContext.

PropertyPlaceHolderConfigurer is a BeanFactoryPostProcessor implementation that reads a property file and uses that property file to replace placeholder variables like ${xyz}. The properties aren’t available as a Properties object.

in Spring 3.1+ you should use the PropertySourcesPlaceholderConfigurer not the PropertyPlaceHolderConfigurer. This implementation is a replacement of PropertyPlaceholderConfigurer and properties are added as a PropertySource and the property source is contributed to the Spring Environment.

This allows you to autowire in the environment and access properties from any sources

@Autowired
private Environment environment;
 
 
public void someMethod(){
 
   String myProp = environment.getProperty("myProp");
}

One thing to note is this is BeanFactoryPostProcessor is applied at per-context basis, which mean it would not share among other child/parent application context.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s