Job ์คํ ๊ด๋ จ ํ๋กํผํฐ
- spring.batch.job.enabled : application context ์ ๋ฑ๋ก๋ Job ์ ์คํ์ ํ์ฑํํ๋ ํ๋กํผํฐ
- true (default) : Job ์ ์คํ ๊ฐ๋ฅํ๋๋ก ํ์ฑํ / false : ๋ชจ๋ Job ์ ์คํ ๋ถ๊ฐ๋ฅํ๋๋ก ์ค์
- spring.batch.job.name : ์คํํ ๋ฐฐ์น Job ์ job name ์ ๊ธฐ์ค์ ๊ธฐ๋ฐ์ผ๋ก ์ ์ธ
- spring.batch.job.name=
- ๊ฐ์ด ์์ผ๋ฉด ๋ชจ๋ ์ก์ ์คํ (spring batch 5.x ๋ถํฐ exception ๋ฐํํ๋ฉฐ ์คํํ์ง ์์.)
- spring.batch.job.name=jobName1
- jobName1 ์ด๋ฆ์ ์ก๋ง ์คํํ๊ฒ ๋ค๋ ์๋ฏธ
- spring.batch.job.name=jobName1,jobName2
- spring batch 4.x : ํด๋น job name ์ multiple batch job ์ ์คํ
- spring batch 5.x : multiple batch job ์ ์ ๊ณตํ์ง ์์ IllegalArgumentException ๋ฐ์
- spring.batch.job.name=${job.name:NONE}
- spring.batch.job.name ์ ๊ฐ์ด ์์ผ๋ฉด ๋ชจ๋ ์ก ์คํ
- ${job.name:NONE} : job.name ์ด ์กด์ฌํ๋ฉด ํน์ ์ก๋ง ์คํํ๊ณ , job.name ์ ๊ฐ์ด ์์ผ๋ฉด ์คํํ์ง ์๊ฒ ์ค์
Spring Batch Job test argument ์ค์ ๋ฐฉ๋ฒ
- @SpringBootTest ์ args option ํ์ฉ
@SpringBatchTest
@SpringBootTest(args = "--job.name=memberDeleteJob")
public class MemberBatchTest {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Autowired
private JobRepositoryTestUtils jobRepositoryTestUtils;
@AfterEach
public void cleanUp() {
jobRepositoryTestUtils.removeJobExecutions();
}
@Test
public void testJob(@Autowired @Qualifier("memberDeleteJob") Job job) throws Exception {
this.jobLauncherTestUtils.setJob(job);
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
Assertions.assertThat(jobExecution.getExitStatus().getExitCode()).isEqualTo(ExitStatus.COMPLETED.getExitCode());
}
}
@JobScope, @StepScope
- Scope
- ์คํ๋ง ์ปจํ
์ด๋์์ ๋น์ด ๊ด๋ฆฌ๋๋ ๋ฒ์
- singleton, prototype, request, sessino, application ์ด ์กด์ฌํ๋ฉฐ ๊ธฐ๋ณธ์ singleton.
- @JobScope , @StepScope
- Job ๊ณผ Step ์ ๋น ์์ฑ๊ณผ ์คํ์ ๊ด์ฌํ๋ ์ค์ฝํ
- proxy ๋ชจ๋๋ก ๊ธฐ๋ณธ ๊ฐ์ผ๋ก ํ๋ ์ค์ฝํ
- @JobScope
- Step ์ ์ธ๋ฌธ์ ์ ์ํ๋ค.
- @Value : jobParameter, jobExecutionContext ๋ง ์ฌ์ฉ ๊ฐ๋ฅ
- @StepScope
- Tasklet ์ด๋ ItemReader, ItemWriter, ItemProcessor ์ ์ธ๋ฌธ์ ์ ์ํ๋ค.
- @Value : jobParameter, jobExecutionContext, stepExecutionContext ์ฌ์ฉ ๊ฐ๋ฅ
Reference
- spring batch ํน์
- spring.batch.job.name
- spring batch test