본문 바로가기

카테고리 없음

[오류 해결] Encountered invalid @Scheduled method : For input String "L"

728x90
반응형

오류 문구

java.lang.IllegalStateException: Encountered invalid @Scheduled method '이름': For input string: "L"

상황

@Scheduled(cron = "0 0 22 L * ?")

매월 말일 23시마다 해당 스케쥴을 돌리고 싶어서 위 소스 작성했으나, 서버를 실행하며 오류 발생

원인

쿼츠에서 동작하는 크론 문법이지만, 스프링 3.X 버전에서는 기본 표현법만 사용이 가능하기 때문에 발생하는 오류로 추정

참고 링크 : https://stackoverflow.com/questions/17357235/how-to-write-cron-expression-to-execute-a-trigger-on-3rd-sunday-of-every-month-a/19447517#19447517

 

How to write Cron expression to execute a trigger on 3rd Sunday of every month at 11 PM?

I want to fire a trigger on 3rd Sunday of every month. In cron expression I used cron="0 0 23 ? * 1#3" But its gives me Exception java.lang.NumberFormatException: For input string: "1#3" a...

stackoverflow.com

해결 방법

1. 28-31로 기간을 정해준다

@Scheduled(cron = "0 0 22 28-31 * ?")

2. 현재 날짜가 해당 월의 마지막 날인 경우에만 실행되도록 조건을 추가한다

LocalDate currDate = LocalDate.now();
YearMonth month = YearMonth.now();
LocalDate lastDate = month.atEndOfMonth();

if(currDate.toString().equals(lastDate.toString())){
	실행하려는 서비스;
}
728x90
반응형