SpringBoot定时任务:使用shedlock解决SpringBoot分布式定时任务重复执行的问题,SpringBoot定时任务SchedulerLock的用法,不使用Redis实现定时任务事务

https://blog.csdn.net/qq_43265673/article/details/108348919

@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S")
public class ShedLockRedisConfig {

    @Value("${spring.profiles.active}")
    private String env;

    @Bean
    public LockProvider lockProvider(RedisConnectionFactory redisConnectionFactory) {
        //环境变量 -需要区分不同环境避免冲突,如dev环境和test环境,两者都部署时,只有一个实例进行,此时会造成相关环境未启动情况
        return new RedisLockProvider(redisConnectionFactory, env);
    }
}
@Scheduled(cron = "0 0/3 * * * ?")
    @SchedulerLock(name = "autoDistributeXiaoshou", lockAtLeastForString = "PT1M", lockAtMostForString = "PT2M")