How to set dynamic value to @PropertySource?

Viewed 7890

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;

}
2 Answers

If you want to use those properties during tests you can leverage new functionality (as of Spring Framework 5.2.5 and Spring Boot 2.2.6):

@DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry) {
    registry.add("cust.name", "some property");
}
Related