Spring Core: Diving into the PropertyPlaceHolderConfigurer

Spring Core: Diving into the PropertyPlaceHolderConfigurer

http://ift.tt/2pHoCPE

In this post, we will externalize the properties used in an application in a property file and will use PropertyPlaceHolderConfigurer to resolve the placeholder at startup time.

Java Configuration for PropertyPlaceHolderConfigurer

@Configuration
public class AppConfig {

    @Bean
    public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
        propertySourcesPlaceholderConfigurer.setLocations(new ClassPathResource("application-db.properties"));
        //propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
        //propertySourcesPlaceholderConfigurer.setIgnoreResourceNotFound(true);
        return propertySourcesPlaceholderConfigurer;
    }
}

java

via DZone.com Feed https://dzone.com

May 12, 2017 at 09:27PM

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