Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 616
CodeSun Avatar asked May 23 '26 11:05

CodeSun


1 Answers

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

like image 88
Michiel Avatar answered May 27 '26 00:05

Michiel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!