IT/Live Coding

[springBoot] spring batch simpleTextReader (ํ…Œ์ŠคํŠธ ์˜์ƒ & ์†Œ์Šค์ฝ”๋“œ ํฌํ•จ)

์•Œ ์ˆ˜ ์—†๋Š” ์‚ฌ์šฉ์ž 2023. 11. 10.

์•„๋ž˜ ํฌ์ŠคํŒ…์—์„œ ์ด์–ด์ง„ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

 

[springBoot] spring batch simpleReader insert other table( feat. JPA)

์•„๋ž˜ ํฌ์ŠคํŒ…์—์„œ ์ด์–ด์ง„ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. [springBoot] spring batch jpa simpleDbReader (feat. simple Reader) ์•„๋ž˜ ํฌ์ŠคํŒ…์—์„œ ์ด์–ด์ง„ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. [springBoot] Simple Spring Batch Tasklet(feat. simple) ์Šคํ”„๋ง ๋ฐฐ์น˜๋ฅผ ์ด์šฉํ•œ ์ •

yaga.tistory.com


๊ตฌ๋ถ„์ž ์—†๋Š” ํ…์ŠคํŠธํŒŒ์ผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์„œ ๋กœ๊ทธ ์ถœ๋ ฅํ•˜๋Š” ๋‹จ์ˆœ ์˜ˆ์ œ

TextJob ๐Ÿ˜ƒ

package com.lsy.sample.springbatchvideo.batch;

import com.lsy.sample.springbatchvideo.dto.OneDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

@Slf4j
@RequiredArgsConstructor
@Configuration
public class TextJob {

    private final JobBuilderFactory jobBuilderFactory;
    private final StepBuilderFactory stepBuilderFactory;
    private static final int chunkSize = 5;

    @Bean
    public Job textjob1_batchBuild() {
        return jobBuilderFactory.get("textJob1")
                .start(textJob1_batchStep1())
                .build();
    }


    @Bean
    public Step textJob1_batchStep1() {
        return stepBuilderFactory.get("testJob1_batchStep1")
                .<OneDto, OneDto>chunk(chunkSize)
                .reader(textJob1_FileReader())
                .writer(OneDto -> OneDto.stream().forEach(i -> {
                    log.debug(i.toString());
                }))
                .build();
    }

    // text reader
    @Bean
    public FlatFileItemReader<OneDto> textJob1_FileReader() {
        FlatFileItemReader<OneDto> flatFileItemReader = new FlatFileItemReader<>();
        flatFileItemReader.setResource(new ClassPathResource("sample/textJob1_input.txt"));
        flatFileItemReader.setLineMapper((line, lineNumber) -> new OneDto(lineNumber + " == " + line));
        return flatFileItemReader;
    }


}

๊ฐœ์ธ ์Šคํ„ฐ๋”” ๊ธฐ๋ก์„ ๋ฉ”๋ชจํ•˜๋Š” ๊ณต๊ฐ„์ด๋ผ ํ‹€๋ฆฐ์ ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ‹€๋ฆฐ ์  ์žˆ์„ ๊ฒฝ์šฐ ๋Œ“๊ธ€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

reference: https://www.youtube.com/watch?v=wy99cPHlMlA&list=PLogzC_RPf25HRSG9aO7qKrwbT-EecUMMR


๋‹ค์Œ ๋‚ด์šฉ

 

[springBoot] spring batch write to new file (feat. file)

์•„๋ž˜ ํฌ์ŠคํŒ…์—์„œ ์ด์–ด์ง„ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. [springBoot] spring batch simpleTextReader ์•„๋ž˜ ํฌ์ŠคํŒ…์—์„œ ์ด์–ด์ง„ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. [springBoot] spring batch simpleReader insert other table( feat. JPA) ์•„๋ž˜ ํฌ์ŠคํŒ…์—์„œ ์ด์–ด์ง„ ๋‚ด์šฉ์ž…

yaga.tistory.com

๋Œ“๊ธ€