springdatabaseshedlock

Spring ShedLock without Database


I want to disable ShedLock with a configuration yml property. So i don't have to create the table shedlock, if it is not necessary. Is there a way to disable Shedlock usage?

I tried to remove @Bean lockProvider but then I got this message:

No qualifying bean of type 'net.javacrumbs.shedlock.core.LockProvider


Solution

  • If you are using ShedLock in combination with the shedlock-spring dependency, there probably is a @EnableSchedulerLock somewhere in your application. Move the LockProvider bean setup together with the annotation to a separate @Configuration class and add a @ConditionalOnProperty annotation, for example:

    @Configuration
    @EnableSchedulerLock
    @ConditionalOnProperty(value = "shedlock.enabled", matchIfMissing = true)
    public class ShedLockConfig {
    
        @Bean
        public LockProvider lockProvider(DataSource dataSource) {
            // ...
        }
    }
    

    And add the property

    shedlock:
      enabled: true
    

    To your application.yml