package com.example.scheduldemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class SchedulDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SchedulDemoApplication.class, args);
}
}
package com.example.scheduldemo.service;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Service
public class SchedulTest {
@Scheduled(cron = "0/5 * * * * ?")
public void SayHello(){
System.out.println("Hello Schedul:"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss:SSS")));
}
}