I created a cron job to run every day at 3:30pm , but it is not working.
Note: Already used: @EnableScheduling
on the main class.
@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
you should annotate your main file or other configuration file with @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);
}
}
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.