不要写死——动态注解值

cron-time: "0/10 * * * * ?"
cron-time2: "0/5 * * * * ?"

@Component
@EnableScheduling
public class Test1 implements SchedulingConfigurer {
    @Value("${cron-time}")
    private String cronTime;


    
    @Scheduled(cron = "${cron-time1}")
    public void editableCronTask() {
        System.out.println(LocalDateTime.now() + "动态注解值-通用");
    }
    
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addCronTask(() -> System.out.println(LocalDateTime.now()+"实现调度接口"), cronTime);
    }
    
}

你可能感兴趣的:(java,servlet,junit)