[ Spring Batch ] 가입인사와 동시에 스프링배치 nullPoint 에러 관련 질문이 있습니다!

559 views
Skip to first unread message

H

unread,
Nov 23, 2020, 12:16:46 AM11/23/20
to Korea Spring User Group Q&A
안녕하세요, 스프링 개발자로 일한 지 2개월된 신입 개발자입니다!
서로 정보도 공유하고 재밌게 황동할 수 있으면 좋겠습니다 :D

가입과 동시에 질문이 있습니다!
현재 스프링부트를 이용해 스프링배치를 구현중입니다!
log 상으로는 READ 를 통한 결과가 출력이 됩니다만, 현재 batch_job_execution_context 테이블의 short_context 에 값이 들어가지 않고, serialized_context의 값이 null 입니다
이 부분만 이틀째 보고 있는데 원인을 도저히 찾기 어려워 선배님들의 조언을 받고 싶습니다!
줄줄이 나열해놔서 죄송합니다ㅠㅠ
어떤 부분이 원인일지 감이 안오는데, 선배님들 조언 좀 부탁드립니다!

아래와 같이 배치 코드를 작성했습니다!
---------------------------------------------------------------------------------------------------------------------------------------------
@AllArgsConstructor
@Slf4j
@Configuration
public class SimpleJobConfiguration {

@Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;
    @Autowired
    DataSource dataSource;
    @Autowired
    EntityManagerFactory entityManagerFactory;
    
    
    
    private static final int chunkSize = 10;
    
    @Bean
    public Job userSystemBatchJob() throws Exception {
        return jobBuilderFactory.get("userSystemBatchJob")
                .start(userSystemBatchStep())
                .build();
    }
    
    @Bean
    public Step userSystemBatchStep() throws Exception {
        return stepBuilderFactory.get("userSystemBatchStep")
                .<UserDTO, UserDTO>chunk(chunkSize)
                .reader(userSystemBatchReader())
                .writer(userSystemBatchWriter())
                .build();
    }

    @Bean
    public JdbcPagingItemReader<UserDTO> userSystemBatchReader() throws Exception {
        return new JdbcPagingItemReaderBuilder<UserDTO>()
                .fetchSize(chunkSize)
                .dataSource(dataSource)
                .rowMapper(new BeanPropertyRowMapper<>(UserDTO.class))
                .queryProvider(userSystemBatchReaderProvider())
                .name("userSystemBatchReader")
                .build();
    }
    
    private JdbcBatchItemWriter<UserDTO> userSystemBatchWriter() {
    return new JdbcBatchItemWriterBuilder<UserDTO>()
    .dataSource(dataSource)
    .sql("UPDATE core.user a SET name = 'batch', id = 'a...@aaa.aaa', en_first_nm = 'aaaaa', en_last_nm = 'aaaaa', birth = '99999999', phone = '99999999999' , status = '11' from trade b where user_no = :user_no")
    .beanMapped()
    .build();
    }

    @Bean
    public PagingQueryProvider userSystemBatchReaderProvider() throws Exception {
        SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean();
        queryProvider.setDataSource(dataSource);
        queryProvider.setSelectClause("distinct user_no");
        queryProvider.setFromClause("from core.user");
        queryProvider.setWhereClause("where status = '10' and secession is not null and not exists (select send_no, recv_no, trade.send_dt from trade where send_no = user_no and status = '10' and trade.send_dt is not null and current_date > (secession + '+10days'))");
        Map<String, Order> sortKeys = new HashMap<>(1);
        sortKeys.put("user_no", Order.DESCENDING);
        queryProvider.setSortKeys(sortKeys);
        return queryProvider.getObject();
    }
    
}
--------------------------------------------------------------------------------------------------------------------------------------------- 

그리고 아래와 같이 에러로그가 출력됩니다..ㅠㅠ

--------------------------------------------------------------------------------------------------------------------------------------------- 
20201123 11:03:46.894 [restartedMain] ERROR o.s.b.c.s.AbstractStep - Encountered an error executing step userSystemBatchStep in job userSystemBatchJob java.lang.NullPointerException: null at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:190) at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:186) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:647) at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:186) at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:410) at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:319) at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:147) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy101.run(Unknown Source) at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786) at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776) at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at com.payhada.batch.PayhadaBatchApplication.main(PayhadaBatchApplication.java:29) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) 20201123 11:03:46.898 [restartedMain] DEBUG j.sqltiming - com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) 1. UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = '{"userSystemBatchReader.read.count":0,"batch.taskletType":"org.springframework.batch.core.step.item.ChunkOrientedTasklet","userSystemBatchReader.start.after":["java.util.LinkedHashMap",{}],"batch.stepType":"org.springframework.batch.core.step.tasklet.TaskletStep"}', SERIALIZED_CONTEXT = NULL WHERE STEP_EXECUTION_ID = 156 {executed in 3 msec} 20201123 11:03:46.902 [restartedMain] INFO o.s.b.c.s.AbstractStep - Step: [userSystemBatchStep] executed in 60ms 20201123 11:03:46.906 [restartedMain] DEBUG j.sqltiming - com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) 62. UPDATE BATCH_STEP_EXECUTION set START_TIME = '11/23/2020 11:12:52.187', END_TIME = '11/23/2020 11:12:52.220', STATUS = 'FAILED', COMMIT_COUNT = 0, READ_COUNT = 2, FILTER_COUNT = 0, WRITE_COUNT = 0, EXIT_CODE = 'FAILED', EXIT_MESSAGE = 'java.lang.NullPointerException at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:190) at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:186) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:647) at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:186) at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:410) at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:319) at org.springframework.batch.core.launch.sup', VERSION = 2, READ_SKIP_COUNT = 0, PROCESS_SKIP_COUNT = 0, WRITE_SKIP_COUNT = 0, ROLLBACK_COUNT = 1, LAST_UPDATED = '11/23/2020 11:12:52.220' where STEP_EXECUTION_ID = 162 and VERSION = 1 {executed in 3 msec} 20201123 11:12:52.227 [restartedMain] DEBUG j.sqltiming - com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) 62. UPDATE BATCH_JOB_EXECUTION set START_TIME = '11/23/2020 11:12:52.040', END_TIME = '11/23/2020 11:12:52.237', STATUS = 'FAILED', EXIT_CODE = 'FAILED', EXIT_MESSAGE = 'java.lang.NullPointerException at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:190) at org.springframework.batch.item.database.JdbcBatchItemWriter$1.doInPreparedStatement(JdbcBatchItemWriter.java:186) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:647) at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:186) at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:410) at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:319) at org.springframework.batch.core.launch.sup', VERSION = 2, CREATE_TIME = '11/23/2020 11:12:52.024', LAST_UPDATED = '11/23/2020 11:12:52.237' where JOB_EXECUTION_ID = 287 and VERSION = 1 {executed in 3 msec} 20201123 11:12:52.258 [restartedMain] INFO o.s.b.c.l.s.SimpleJobLauncher - Job: [SimpleJob: [name=userSystemBatchJob]] completed with the following parameters: [{}] and the following status: [FAILED] in 197ms 20201123 11:12:52.259 [restartedMain] INFO o.s.b.d.a.ConditionEvaluationDeltaLoggingListener - Condition evaluation unchanged 20201123 11:13:00.093 [RMI TCP Connection(13)-127.0.0.1] INFO o.a.c.c.C.[.[.[/] - Initializing Spring DispatcherServlet 'dispatcherServlet' 20201123 11:13:00.093 [RMI TCP Connection(13)-127.0.0.1] INFO o.s.w.s.DispatcherServlet - Initializing Servlet 'dispatcherServlet' 20201123 11:13:00.098 [RMI TCP Connection(13)-127.0.0.1] INFO o.s.w.s.DispatcherServlet - Completed initialization in 5 ms

 --------------------------------------------------------------------------------------------------------------------------------------------- 
줄줄 나열만 해놔서 죄송합니다ㅜㅠ

Sanghyuk Jung

unread,
Nov 23, 2020, 12:38:07 AM11/23/20
to ks...@googlegroups.com
writer에서 쓰는 쿼리에  'user_no = :user_no' 부분이 있는데요 UserDTO에 멤버변수로 String userNo 가 선언되어 있다면 ':userNo' 로 파라미터가 들어가야할듯합니다.
위의 에러메시지가 이것때문인지는 확신은 안 가지만요.


'

2020년 11월 23일 (월) 오후 2:16, H <hyel...@gmail.com>님이 작성:
--
이 메일은 Google 그룹스 'Korea Spring User Group Q&A' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ksug+uns...@googlegroups.com에 이메일을 보내세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ksug/9b860b82-cc3b-4e3a-abea-c2d582966904n%40googlegroups.com을(를) 방문하세요.

H

unread,
Nov 23, 2020, 1:16:38 AM11/23/20
to Korea Spring User Group Q&A
답변 정말 감사합니다!
현재 UserDTO 에 String user_no 로 선언되어 있습니다!
reader 에서 출력된 user_no 가 writer 로 넘어가지 않는 것인지, 왜 null 로 들어가는지 이해가 안되네요ㅠㅠ
reader 에서 값을 넘겨주는 부분에서 문제가 생기는 걸까요..?
2020년 11월 23일 월요일 오후 2시 16분 46초 UTC+9에 H님이 작성:
Reply all
Reply to author
Forward
0 new messages