Spring Boot Batch - stellaxxx/batch GitHub Wiki
Spring Batch + Boot
- Batch ์ํ์ ๋ํด Boot์์ ๊ฐ๋จํ๊ฒ ์ฒ๋ฆฌํด ์ค. (@EnableBatchProcessing (from Spring Batch))
- ๋ชจ๋ Job์ ์คํ์ํค๋๊ฒ ๋ํดํธ์ด์ง๋ง ํน์ JOB์ ์ง์ ํ ์๋ ์์. (ํ๋กํผํฐ ํ์ผ์ ํตํด ์ง์ )
Spring Batch auto configuration is enabled by adding @EnableBatchProcessing (from Spring Batch) somewhere in your context. By default it executes all Jobs in the application context on startup (see JobLauncherCommandLineRunner for details). You can narrow down to a specific job or jobs by specifying spring.batch.job.names (comma separated job name patterns). If the application context includes a JobRegistry then the jobs in spring.batch.job.names are looked up in the registry instead of being autowired from the context. This is a common pattern with more complex systems where multiple jobs are defined in child contexts and registered centrally. See BatchAutoConfiguration and @EnableBatchProcessing for more details.
- Boot ์์ ๋ด๋ถ์ ์ผ๋ก JobLauncherCommandLineRunner๋ฅผ ์์ฑ, ์ง์ ํ JOB๋ค์ ์คํ์ํจ๋ค.
- Job ๊ตฌ๋ ํ๊ฒฝ์ ๋ํด ๊ฐ๋จํ๊ฒ ์ค์ ๊ฐ๋ฅ
@Configuration
@ComponentScan
@EnableBatchProcessing
@EnableAutoConfiguration
public class MelonApplication {
public static void main( String [] args ) {
SpringApplication app = new SpringApplication(MelonApplication . class);
app .run(args );
}
}
JOB ์คํ ๊ด๋ จ
- Job Initialize๋ฅผ ํ ์ ์๋๋ก ํ๋กํผํฐ ์ค์
spring.batch.job.enabled=true #default๊ฐ true์. - job Name์ ์ง์ ํ์ง ์์ผ๋ฉด ๋ฑ๋ก๋ ๋ชจ๋ JOB์ด ์คํ๋๋ฏ๋ก ์ฃผ์!!
- main ํด๋์ค ์คํ ์ ์ปค๋งจ๋๋ผ์ธ ํ๋ผ๋ฉํฐ๋ก job name ์ง์
--spring.batch.job.names=myJob - ๋ณต์๊ฐ์ JOB๋ ์ง์ ๊ฐ๋ฅํจ. (์ฝค๋ง๋ก ๊ตฌ๋ถ)
JOB ํ๋ผ๋ฉํฐ
- ์ปค๋งจ๋๋ผ์ธ ํ๋ผ๋ฉํฐ๋ก ์ค ๊ฒฝ์ฐ @Value ์ด๋ ธํ ์ด์ ์ ํตํด ์ฌ์ฉ ๊ฐ๋ฅํจ
@Value("${date}")
private String date;