SpringBoot
[SpringBoot] @Scheduled
prettyNoona
2023. 2. 23. 14:23
1. ApiApplication.java 파일에 아래와 같이 작성
package com.cesco.api.폴더이름;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.context.annotation.*;
@Configuration
@EnableScheduling
@SpringBootApplication
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
2. 함수를 담은 클래스에 Annotation 선언
import org.springframework.stereotype.Component;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@Component
@EnableScheduling
public class ScheduleTask {
@Scheduled(cron=" 10 * * * * *")
public void INVENTORYSERL_del() throws Exception{
service.INVENTORYSERL_del(YMDate.format(cal.getTime()));
}
}
3. @Scheduled 실행 할 함수 위에 지정
@Scheduled(cron=" 10 * * * * *")
public void INVENTORYSERL_del() throws Exception{
service.INVENTORYSERL_del(YMDate.format(cal.getTime()));
}
>> 스케줄을 돌릴 때 메소드에 리턴타입과 매개변수를 줄 수 없다