Monday, February 1, 2021

spring PropertyPlaceholderConfigurer and context:property-placeholder

<context:property-placeholder ... />

 is the XML equivalent to the PropertyPlaceholderConfigurer


https://dzone.com/articles/spring-core-diving-into-the-propertyplaceholdercon

https://stackoverflow.com/questions/7542506/spring-propertyplaceholderconfigurer-and-contextproperty-placeholder


@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;

    }
}
--------------------------------------------
@Configuration
@PropertySource("/foo/bar/services.properties")
public class ServiceConfiguration { 

    @Autowired Environment environment; 

    @Bean public javax.sql.DataSource dataSource( ){ 
        String user = this.environment.getProperty("ds.user");
        ...
    } 
}

No comments:

Post a Comment

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass