简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM