简体   繁体   English

spring boot 中的 Cron 作业未运行

[英]Cron job in spring boot not running

I created a cron job to run every day at 3:30pm , but it is not working.我创建了一个每天下午 3:30运行的 cron 作业,但它不起作用。

Note: Already used: @EnableScheduling on the main class.注意:已在主类上使用: @EnableScheduling

@Scheduled(cron = "0 30 15 * * *")
public void sendNotificaions() {
// METHOD IMPLEMENTATION        
}

I did the above code but it is not working.我做了上面的代码,但它不工作。

Please suggest a solution.请提出解决方案。 Thanks in advance.提前致谢。

Spring Scheduling春季调度

Allow you to execute tasks for the specific time period允许您执行特定时间段的任务

Create your Component创建你的组件

package com.jb.cron.jobs;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by kobis on 24 Dec, 2022
 */
@Component
public class MyJob {

    @Scheduled(cron = "0 40 14 * * *") // Every day at 14:40:00
    public void yalla(){
        System.out.println("Woho");
    }
}

Don't forget to activate proxy to enable Spring Scheduling不要忘记激活代理以启用 Spring Scheduling

you should annotate your main file or other configuration file with @EnableScheduling您应该使用@EnableScheduling注释您的主文件或其他配置文件

package com.jb.cron;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class CronApplication {

    public static void main(String[] args) {
        SpringApplication.run(CronApplication.class, args);
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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