๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Spring/Spring Batch

Spring Batch (10) @JobScope, @StepScope

by ์ฃผ๋ฐœ2 2022. 12. 8.
๋ฐ˜์‘ํ˜•

๐Ÿ”—  Spring Batch @JobScope, @StepScope

์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ๋Š” JobParametersValidator์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด์•˜๋Š”๋ฐ์š” ๊ฐ„๋žตํžˆ ์ •๋ฆฌํ•ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • Job ์‹คํ–‰ ์‹œ ํ•„์ˆ˜์ ์ธ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฒ€์ฆํ•˜๋Š” ์—ญํ• ์ž…๋‹ˆ๋‹ค.
  • ๊ธฐ๋ณธ์ ์œผ๋กœ DefaultJobParametersValidator ๊ตฌํ˜„์ฒด๋ฅผ ์ง€์›ํ•˜๋ฉฐ, JobParametersValidator ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ํ•˜์—ฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฒ€์ฆํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด๋ฒˆ์— ์ •๋ฆฌํ•  @JobScope, @StepScope๋Š” ์ง€๋‚œ Spring Batch Job ํฌ์ŠคํŒ…์—์„œ JobParameters๋ฅผ ๋ฐ›์„ ๋•Œ ๊ฐ„๋žตํžˆ ์‚ฌ์šฉ์„ ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

  • ์ฝ”๋“œ๋กœ ์ƒ์„ฑ : JobParameterBuilder
  • SPEL ์‚ฌ์šฉ : @Value(“#{jobParameter[requestDate]}”) - @JobScope, @StepScope ์„ ์–ธ์ด ํ•„์ˆ˜
    • @JobScope, @StepScope๋Š” Job, Step์ด ์‹คํ–‰๋˜๋Š” ์‹œ์ ์— Bean์ด ์ƒ์„ฑ๋˜๋„๋ก Bean์˜ ์ƒ์„ฑ์‹œ์ ์„ ์ง€์—ฐ์‹œํ‚ค๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. @Value ์–ด๋…ธํ…Œ์ด์…˜์˜ ๊ฒฝ์šฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋  ๋•Œ ๋ฐ”์ธ๋”ฉ์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— @JobScope, @Stepcope ์–ด๋…ธํ…Œ์ด์…˜์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด NullPointerException ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์กฐ๊ธˆ ๋” ์ž์„ธํžˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

๐Ÿ”—  ๊ธฐ๋ณธ ๊ฐœ๋… ๋ฐ ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •

1. Scope

  • Scope๋Š” ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์—์„œ Bean์ด ๊ด€๋ฆฌ๋˜๋Š” ๋ฒ”์œ„๋ฅผ ๋œปํ•ฉ๋‹ˆ๋‹ค.
  • ์ข…๋ฅ˜๋Š” singleton(default), prototype, request, session, application์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.
    • ๊ฐ ์ข…๋ฅ˜๋Š” Bean ์ •์˜์— ๋Œ€ํ•ด ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ ๋‚ด์— ๋‹จ ํ•˜๋‚˜๋งŒ ์กด์žฌํ•˜๋Š”์ง€(singleton), ๋‹ค์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€(prototype), ๋ผ์ดํ”„ ์‚ฌ์ดํด์ด Http Request์ธ์ง€ ๋“ฑ์˜ ํŠน์ง•์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 
    • ์ž์„ธํ•œ ๋‚ด์šฉ์€ ํ•ด๋‹น ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

2. Spring Batch Scope (@JobScope, @StepScope)

  • Spring Batch Scope๋Š” Job, Step์˜ Bean ์ƒ์„ฑ ๋ฐ ์‹คํ–‰์— ๊ด€์—ฌํ•˜๋Š” Scope์ž…๋‹ˆ๋‹ค.
  • ํ”„๋ก์‹œ ๋ชจ๋“œ๋ฅผ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ๊ฐ€์ง€๋Š” Scope ์ž…๋‹ˆ๋‹ค.

  • ํ•ด๋‹น ์Šค์ฝ”ํ”„๊ฐ€ ์„ ์–ธ๋˜๋ฉด ๋นˆ์˜ ์ƒ์„ฑ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ๋™ ์‹œ์ ์ด ์•„๋‹Œ Bean์˜ ์‹คํ–‰ ์‹œ์ ์— ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค(Lazy Binding)
    • ์ฆ‰ Job, Step์ด ์‹คํ–‰๋˜๋Š” ์‹œ์ ์— Bean์ด ์ƒ์„ฑ๋˜๋Š”๋ฐ์š”, ์ด๋Š” @Value ์–ด๋…ธํ…Œ์ด์…˜์˜ ๊ฒฝ์šฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋  ๋•Œ ๋ฐ”์ธ๋”ฉ์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Scope๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ์‹œ์ ์„ ์ง€์—ฐ์‹œ์ผœ ๋ฐ”์ธ๋”ฉ์ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.
    • ์•„๋ž˜์ฒ˜๋Ÿผ SpEL ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ์„ ์–ธํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@Value("#{jobParameters[ํŒŒ๋ผ๋ฏธํ„ฐ๋ช…]}") , @Value("#{jobExecutionContext[ํŒŒ๋ผ๋ฏธํ„ฐ๋ช…]}")

 

  • ํ”„๋ก์‹œ ๋ชจ๋“œ๋กœ Bean์ด ์„ ์–ธ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ๋™ ์‹œ์ ์—๋Š” Bean์˜ ํ”„๋ก์‹œ ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋˜๊ณ , ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์‹œ์ ์—์„œ ์‹ค์ œ ๋นˆ์„ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. (AOP)
  • ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ ์‹œ ๊ฐ ์Šค๋ ˆ๋“œ๋งˆ๋‹ค ์ƒ์„ฑ๋œ ์Šค์ฝ”ํ”„ ๋นˆ์ด ํ• ๋‹น๋˜๊ธฐ์— Thread-safeํ•˜๊ฒŒ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

3. @JobScope

  • Step ์„ ์–ธ๋ฌธ์— ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
  • @Value: jobParameter, jobExecutionContext๋งŒ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

4. @StepScope

  • Tasklet์ด๋‚˜ ItemReader, ItemWriter, ItemProcessor ์„ ์–ธ๋ฌธ์— ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
  • @Value: jobParameter, stepExecutionContext ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

 

๐Ÿ”—  ์˜ˆ์ œ์ฝ”๋“œ

Step์—๋Š” @JobScope ์„ ์–ธ๊ณผ @Value(jobParameters)๋ฅผ ์„ ์–ธํ•˜์˜€๊ณ , Tasklet์—๋Š” @StepScope์™€ @Value(jobExecutionContext)๋ฅผ ์„ ์–ธํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

 

jobParameters๋Š” ์‹คํ–‰ํ•  ๋•Œ ์ธ์ž๋กœ ๊ฐ’์„ ์ฃผ์ž…ํ•˜์—ฌ ๋ฐ›๊ณ , jobExecutionContext๋Š” ์•„๋ž˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์ปค์Šคํ…€ Listener ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์—ฌ ๊ฐ’์„ ์„ค์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

JobListener ํด๋ž˜์Šค๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜์—ฌ JobExecutionListener ํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ , ์žก์„ ์‹คํ–‰ํ•˜๊ธฐ ์ „(beforeJob) jobExecutionContext์— "name" : "Lee" ์˜ ๊ฐ’์„ put ํ•ฉ๋‹ˆ๋‹ค.

 

ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์ธ์ž(Program Arguments): --job.name=scopeJob message="JuHyuns"

 

๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ๊ธฐ์กด์— ์„ค์ •ํ•œ ๊ฐ’๋“ค์ด ์ •์ƒ์ ์œผ๋กœ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋งŒ์•ฝ @JobScope๋ฅผ ์ฃผ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ์‹คํ–‰ํ•ด ๋ณด๋ฉด JobParameters๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

 

๐Ÿ”—  ์•„ํ‚คํ…์ฒ˜

1. Proxy ๊ฐ์ฒด ์ƒ์„ฑ

  • @JobScope, @StepScope ์–ด๋…ธํ…Œ์ด์…˜์ด ์„ ์–ธ๋˜๋ฉด ๋‚ด๋ถ€์ ์œผ๋กœ Bean์˜ Proxy ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • ์ฆ‰, Job ์‹คํ–‰ ์‹œ Proxy ๊ฐ์ฒด๊ฐ€ ์‹ค์ œ ๋นˆ์„ ํ˜ธ์ถœํ•ด์„œ ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.

2. JobScope, StepScope

  • Proxy ๊ฐ์ฒด์˜ ์‹ค์ œ ๋Œ€์ƒ์ด ๋˜๋Š” ๋นˆ์„ ๋“ฑ๋กํ•˜๊ณ  ํ•ด์ œํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
  • ์‹ค์ œ ๋นˆ์„ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” JobContext, StepContext๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

3. JobContext, StepContext

  • ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ƒ์„ฑ๋œ ๋นˆ์„ ์ €์žฅํ•˜๋Š” ์ปจํ…์ŠคํŠธ ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
  • Job์˜ ์‹คํ–‰ ์‹œ์ ์—์„œ Proxy ๊ฐ์ฒด๊ฐ€ ์‹ค์ œ ๋นˆ์„ ์ฐธ์กฐํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

4. ์Šคํ”„๋ง ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ๋™ ~ @Value ๋ฐ”์ธ๋”ฉ์ด ์ฒ˜๋ฆฌ๋˜๊ธฐ๊นŒ์ง€์˜ ๊ณผ์ •

@JobScope, @StepScope ์•„ํ‚คํ…์ฒ˜

  1. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ตฌ๋™๋˜๋ฉด ์Šคํ”„๋ง์˜ ApplicationContext๊ฐ€ Bean์„ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
  2. @JobScope (ํ˜น์€ @StepScope) ์–ด๋…ธํ…Œ์ด์…˜์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
    • ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๊ธฐ๋ณธ์ ์ธ ์‹ฑ๊ธ€ํ†ค Bean์„ ์ƒ์„ฑํ•˜๊ณ , @Value ์–ด๋…ธํ…Œ์ด์…˜ ์„ ์–ธ ์‹œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
    • ์กด์žฌํ•œ๋‹ค๋ฉด ํ•ด๋‹น Bean์˜ Proxy ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
    • @Scope(value = "job", proxyMode = ScopedProxyMode.TARGET_CLASS)
  3. ์„ค์ •์ด ๋๋‚˜๋ฉด ์Šคํ”„๋ง ์ดˆ๊ธฐํ™”๊ฐ€ ์™„๋ฃŒ๋˜๊ณ  Job์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. (JobLauncher)
  4. Job์€ Step์˜ ์‹ค์ œ Bean์ด ์•„๋‹Œ Proxy ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  5. ํ”„๋ก์‹œ ๊ฐ์ฒด๋Š” ์‹ค์ œ Step ๋ฉ”์„œ๋“œ(scopeStep1)๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์‹ค์ œ Bean ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ์ด ์‹œ์ ์— Step Bean์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  6. 5.์—์„œ ํ”„๋ก์‹œ ๊ฐ์ฒด๊ฐ€ ์‹ค์ œ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ฐธ์กฐํ•  Bean์„ JobScope์—์„œ ์ฐพ์Šต๋‹ˆ๋‹ค. (JobScope๋Š” JobContext๋ฅผ ํ†ตํ•ด ์ฐพ์Šต๋‹ˆ๋‹ค.)
  7. JobContext์—์„œ ์‹ค์ œ Bean์ด ์กด์žฌํ•˜๋ฉด Bean์„ ๊บผ๋‚ด ์ฐธ์กฐํ•˜์—ฌ ์‹ค์ œ Step์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  8. JobContext์—์„œ ์‹ค์ œ Bean์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด ์Šคํ”„๋ง์˜ BeanFactory๋ฅผ ํ†ตํ•ด ์‹ค์ œ Step์„ ์ƒ์„ฑํ•˜๊ณ , ์ด ์‹œ์ ์—์„œ ์‹ค์ œ scopeStep1() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด์„œ Bean์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ @Value ๋ฐ”์ธ๋”ฉ ์ฒ˜๋ฆฌ๋„ ๊ฐ™์ด ์ง„ํ–‰์ด ๋ฉ๋‹ˆ๋‹ค.
  9. ๊ทธ ํ›„ ์ƒ์„ฑ๋œ Step Bean์„ JobContext์— ์ €์žฅํ•˜๊ณ , ์ดํ›„์—๋Š” JobContext์—์„œ Bean์„ ๋ฐ”๋กœ ๊บผ๋‚ด์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

5. ๋‚ด๋ถ€ ์ฝ”๋“œ

JobScope, StepScope ๋ชจ๋‘ ๋‚ด๋ถ€ ๋กœ์ง์€ ๋น„์Šทํ•˜๊ธฐ์— JobScope์˜ ์ฝ”๋“œ๋งŒ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

AbstractBatchConfiguration ์ถ”์ƒ ํด๋ž˜์Šค ๋‚ด๋ถ€์— ์กด์žฌํ•˜๋Š” ScopeConfiguration ํด๋ž˜์Šค์—์„œ StepScope, JobScope๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

์œ„ ์ฝ”๋“œ์—์„œ @Configuration(proxyBeanMethods = false)๋กœ ์„ค์ •์ด ๋˜์–ด์žˆ๋Š”๋ฐ์š”, ์ด๋Š” ํ”„๋ก์‹œ๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š๊ณ  ์ค‘๋ณต ์ฝ”๋“œ์— ์˜ํ•ด ๋™์ผํ•œ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜๋”๋ผ๋„ ์‹ฑ๊ธ€ํ†ค์œผ๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 

๊ด€๋ จํ•ด์„œ๋Š” ์•„๋ž˜ ๋งํฌ๋“ค์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

 

JobScope

JobScope ํด๋ž˜์Šค์˜ get() ๋ฉ”์„œ๋“œ์—์„œ JobContext๋ฅผ ํ†ตํ•ด Bean์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

Bean์ด ์กด์žฌํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์ƒ์„ฑ & ์ €์žฅ์„ ํ•˜๊ณ , ์กด์žฌํ•  ๊ฒฝ์šฐ Bean์„ ๊ฐ€์ ธ์™€ ๋ฐ”๋กœ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.

 

 

26๋ผ์ธ์—์„œ Job์˜ start() ๋ฉ”์„œ๋“œ์—์„œ Step ํ˜ธ์ถœ ์‹œ ์‹ค์ œ Step์ด ์•„๋‹Œ Proxy๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

 

 

 

SimpleStepHandler

์œ„ 115๋ผ์ธ์˜ step.getName() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ์ˆœ๊ฐ„ Proxy ๊ฐ์ฒด๊ฐ€ ์ฐธ์กฐํ•  ์‹ค์ œ Bean์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

(์œ„ step์€ ์‹ค์ œ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์ „์ด๋ฏ€๋กœ Proxy ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.)

 

(์ขŒ) JdkDynamicAopProxy.invoke / (์šฐ) AbstractStep.getName()

step.getName() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด ๋ณด๋ฉด AbstractStep ์ถ”์ƒ ํด๋ž˜์Šค์˜ getName() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•˜์ง€๋งŒ Proxy ๊ฐ์ฒด์ด๋ฏ€๋กœ JdkDynamicAopProxy ํด๋ž˜์Šค์˜ invoke() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. 

 

JdkDynamicAopProxy

Proxy์˜ targetSoucre๊ฐ€ ์‹ค์ œ Bean์ธ scopeStep1์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

JdkDynamicAopProxy.invoke()
JobScope

Proxy์—์„œ ์‹ค์ œ ์ฐธ์กฐํ•  Bean์„ ๊ตฌํ•  ๋•Œ(์œ„ ์‚ฌ์ง„, 195๋ผ์ธ) ํ•„์š”ํ•œ๊ฒŒ JobScope์ž…๋‹ˆ๋‹ค.

 

 

JobScope

JobScope์˜ get() ๋ฉ”์„œ๋“œ์—์„œ ์ตœ์ดˆ Job ํ˜ธ์ถœ ์‹œ JobContext ๋‚ด์— ์‹ค์ œ Bean์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ 185~186 ๋ผ์ธ์„ ํ†ตํ•ด Bean์„ ์ƒ์„ฑํ•˜๊ณ (185 ๋ผ์ธ), JobContext์— ์‹ค์ œ Bean์„ ์ €์žฅ(186 ๋ผ์ธ)ํ•ฉ๋‹ˆ๋‹ค. 

๋˜ํ•œ ์ด๋•Œ ์‹ค์ œ Step์ธ scopeStep1() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

 

 

ํ•˜์ง€๋งŒ ํ˜„์žฌ ์ €์˜ ์ƒํ™ฉ์€ Job์„ ์ฒ˜์Œ ์‹คํ–‰ํ•œ ๊ฒŒ ์•„๋‹Œ ๋‘ ๋ฒˆ์งธ ์‹คํ–‰ํ•œ ์ƒํ™ฉ์ด๋ฏ€๋กœ ์ธ์ž์ธ name์— ํ•ด๋‹นํ•˜๋Š” ์‹ค์ œ Bean์„ JobContext์—์„œ ๋ฐ”๋กœ ๊ฐ€์ ธ์˜จ ํ›„ ๋ฆฌํ„ดํ•˜๊ณ , ์ดํ›„ AbstractStep ์ถ”์ƒ ํด๋ž˜์Šค์˜ getName() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ๊ฐ’์„ ์–ป์Šต๋‹ˆ๋‹ค.

 

 

์ด์ƒ์œผ๋กœ @JobScope, @StepScope์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์ •๋ฆฌํ•˜๋ฉด์„œ๋„ ์–ด๋ ค์šด ๋‚ด์šฉ๋„ ๋งŽ์•˜๊ณ , ์ž˜๋ชป ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ด ์žˆ์„์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค...๐Ÿ˜‚

 

๋‹ค์Œ๋ถ€ํ„ด Spring Batch์—์„œ ์ฒญํฌ ํ”„๋กœ์„ธ์Šค ๋ฐฉ์‹์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

์ฐธ๊ณ  ๋ฌธ์„œ

 

๋ฐ˜์‘ํ˜•

'Spring > Spring Batch' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Spring Batch (12) Retry  (2) 2023.03.04
Spring Batch (11) Repeat  (0) 2023.01.15
Spring Batch (9) JobParametersValidator  (0) 2022.11.13
Spring Batch (8) JobLauncher  (0) 2022.11.11
Spring Batch (7) JobRepository  (0) 2022.11.08

๋Œ“๊ธ€