Spring Boot @EnableScheduling conditionally

前端 未结 4 1777
慢半拍i
慢半拍i 2021-02-20 03:53

Is there a way to make @EnableScheduling conditional based on an application property? also is it possible to disable controllers based on properties too?

What I\'m tryi

4条回答
  •  一整个雨季
    2021-02-20 04:17

    I ended up creating a separate @Configuration class for scheduling and used the @ConditionalOnProperty annotation to toggle scheduling

    @Configuration
    @EnableScheduling
    @ConditionalOnProperty(prefix = "scheduling", name="enabled", havingValue="true", matchIfMissing = true)
    public class SchedulerConfig {
    
    }
    

    in my application.yml file I then added

    scheduling:
      enabled: true
    

提交回复
热议问题