使用StaxEventItemWriter时无法创建动态文件名

时间:2019-11-07 12:10:30

标签: spring spring-batch itemwriter

我正在扩展StaxEventItemWriter以编写自定义ItemWriter,以便可以在运行时动态创建文件名。 该文件名可以很好地创建,但是在尝试写入数据时出现以下问题。

year   month  count  reason_a  reason_c  
2001       1      1         1         0
2001       2      3         0         0
2001       3      4         0         4
2005       1      7         4         3

添加了以下代码,但不起作用。

org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.reflect.InvocationTargetException
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:486)
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272)
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
    at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
    at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
    at com.santanderuk.carde.gassaudittransform.GassAuditTransformApplication.main(GassAuditTransformApplication.java:24)
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.batch.item.xml.StaxUtils.getResult(StaxUtils.java:116)
    at org.springframework.batch.item.xml.StaxEventItemWriter.createStaxResult(StaxEventItemWriter.java:532)
    at org.springframework.batch.item.xml.StaxEventItemWriter.write(StaxEventItemWriter.java:739)
    at com.santanderuk.carde.gassaudittransform.writer.IncomeExpenditureStaxWriter.write(IncomeExpenditureStaxWriter.java:67)
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274)
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199)
    at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
    ... 20 common frames omitted
Caused by: java.lang.IllegalArgumentException: StAXResult(XMLEventWriter) with XMLEventWriter == null
    at javax.xml.transform.stax.StAXResult.<init>(StAXResult.java:90)
    at org.springframework.util.xml.StaxUtils.createStaxResult(StaxUtils.java:145)
    ... 34 common frames omitted

0 个答案:

没有答案