Search code examples
spring-bootspring-batch

Load @configuration based on property in spring boot


I am learning spring batch, and trying to load job configuration based on some property. Is this possible, can we load @Configuration classes based on some property. If yes how to achieve that?


Solution

  • Yes, you just need to use @ConditionalOnProperty in your @Configuration class as follows:

    @Configuration
    @ConditionalOnProperty(name = {"your-property-name"}, havingValue = "true")
    public class ConditionalConfiguration {}
    

    You can find more information in the following online resources: