I want to set dynamic property source value using @PropertySource annotation. Can any one tell me how to achieve this? For the below I have pass properties file name dynamically.
@Configuration
@PropertySource("classpath:message.properties")
public abstract class AbstractCommonAMQPConfiguration {
@Value("${cust.name}")
private String custName;
@Value("${cust.id}")
private String custId;
}
I'm not sure how to do it with @PropertySource
but you can define a PropertySourcesPlaceholderConfigurer
programmatically:
private int some_value = 1;
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("test" + some_value + ".properties"));
return propertySourcesPlaceholderConfigurer;
}
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