스프링 배치를 동작하다가 다음과 같은 에러가 발생였다.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

java.lang.IllegalStateException: Failed to execute CommandLineRunner
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:787) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    
...

Caused by: org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={targetDt=2020-09-11}.  If you want to run this job again, change the parameters.
...

실행 오류가 발생하면서 어쩌구 저쩌구 하는데.. 정답은 아래 문장에 있었다.

 

A job instance already exists and is complete for parameters={targetDt=2020-09-11}.  

> 동일한 파라미터를 가진 Job을 이미 실행했고 완료되었어.

If you want to run this job again, change the parameters.

> 다시 동작하고 싶으면 파라미터를 변경해.

 

그렇다.. 스프링 배치는 동일한 파라미터로는 다시 작동이 불가능하다.

그렇다면 파라미터를 변경해주면 된다!  "version=2"를 추가해줬다. 

잘 동작한다 ㅎㅎ


(참고) 젠킨스에 배치를 등록할 때는 빌드 ID를 version으로 추가했었다.

targetDt="$(date --date="$date - 24 hours" +'%Y-%m-%d')"
java -jar -Dspring.profiles.active=real ./work/target/batch-0.0.1-SNAPSHOT.jar version=$BUILD_ID targetDt="${targetDt}"