Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- springbatch
- Spring CORS
- Spring Entity
- SpringBatch 스키마
- editor Quill
- JPA Update\
- Spring JPA
- 텍스트가 많은 경우
- JPA Insert
- react forwardRef
- react link
- react Quill
- react
- react quill custom
- spring builder
- javascript 함수
- spring security
- spring
- Docker Windows 설치
- Spring Controller return
- springbatch chunk
- javascript 기초
- 코드 중복제거
- react react-router-dom v6
- react Page
- javascrpit 기초
- react jsx if
- Spring DTO
- Javascript
- step 테이블
Archives
- Today
- Total
천천히 알아보는 코딩공부
[SpringBatch] Chunk 기반 실행 본문
jconn4, log4jdbc-log4j2-jdbc4.1 사용했습니다.
SpringBatchApplication
public class SpringBatchApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBatchApplication.class, args);
}
}
config/MybatisConfig
@Configuration
public class MybatisConfig {
@Bean
@BatchDataSource
@Qualifier("datasource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSourceDB() { return DataSourceBuilder.create().build(); }
@Bean
public SqlSessionFactory dbSqlSessionFactory() throws Exception {
SqlSessionFactoryBean sqlSession = new SqlSessionFactoryBean();
sqlSession.setDataSource(dataSourceDB());
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resource = resolver.getResources("classpath:Mapper/Mapper.xml*");
sqlSession.setMapperLocation(resource);
return sqlSession.getObject();
}
@Bean(name ="dbSqlSessionTemplate")
public SqlSessionTemplate dbSqlSessionTemplate(@Qualifier("dbSqlSessionFactory")SqlSessionFactory
SqlSessionFactory)
{
return new SqlSessionTemplate(SqlSessionFactory);
}
@Bean
public PlatformTransactionManager dbTranscationManager(){
return new DataSourceTransactionManager(dataSourceKISDB());
}
}
application.yml
spring:
config:
activate:
local:
on-profile:local
datasource:
jdbc-url: jdbc:log4jdbc:sybase:Tds:ip:port
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
databaseType: sybase
username: id
password: password
spring:
batch:
job:
names: ${job.name:NONE}
jdbc:
initialize-schema: never
mybatis:
mapper-locations: classpath:Mapper/*.xml
Processor/CustomItemProcessor
@Slf4j
@Component
public class CustomItemProcessor implements ItemProcesor<SelectKey, SelectKey> {
@Override
public SelectKey process(SelectKey list) throws Exception {
log.info("실행됨");
return list;
}
}
Reader/CustomItemReader
@Slf4j
public class CustomItemReader implements ItemReader<SelectKey> {
@Autowired
private SpringBatchDAO springBatchDAO;
private List<SelectKey> list;
private Iterator<selectKey> dataIterator;
@Override
public SelectKey read() throws Exceptions, UnexpectedInputException, ParseException,
NonTransientResourceException {
if(dataIteratir == null) {
list = springBatchDao.SearchKey();
dataIterator = list.iterator();
}
if(dataIterator.hasNext()) {
return dataIterator.next();
} else {
return null;
}
}
}
Writer/CustomItemWriter
@Slf4j
@NoArgsConstructor
public class CustomItemWriter implements ItemWriter<SelectKey> {
@Autowired
private SpringBatchDAO springBatchDAO;
@Override
public void write(List<? extends SelectKey> items) throws Exception{
for(SelectKey item : items)
{
if(item.getBizno.length() == 10)
{
....
}
}
}
}
Configuration
@Slf4j
@RequiredArgsConstructor
@Configuration
public class RetryConfiguration {
private final JobBuilderFactory jobBuilderFactory;
private final SeptBuilderFactory stepBuilderFactory;
@Bean
public Job job() throws Exception{
return jobBuilderFactory.get("job")
.start(step1())
.build();
}
@Bean
public Step step1() throws Exception{
log.info("step1 실행됨");
return stepBuilderFactory.get("step1")
,<SelectKey, SelectKey>chunk(1) // 청크사이즈
.reader(ItemReader())
.writer(writer())
.build();
}
@Bean
public ItemReader<SelectKey> ItemReader() throws Exception {
return new CustomItemReader();
}
@Bean
public ItemProcessor<SelectKey, SelectKey> processor() {
return new CustomItemProcessor();
}
@Bean
public ItemWriter<? super SelectKey> writer() {
return new CusomItemWriter();
}
}
'Java > SpringBatch' 카테고리의 다른 글
[SpringBatch] DB 스키마 설명 및 세팅 (2) (0) | 2023.04.20 |
---|---|
[SpringBatch] DB 스키마 설명 및 세팅 (0) | 2023.04.20 |
[SpringBatch] 스프링 배치 실행 순서 (0) | 2023.04.18 |
Comments