Spring Batch StaxEventItemWriter фактически не записывает файл - PullRequest
0 голосов
/ 15 мая 2019

У меня проблема с тем, что мое Spring Batch Application, часть моей работы, читает из PostgresDB, а затем записывает в файл XML.Задание отображается как выполненное (DB to XML: это шаг), но когда я иду в свой каталог, файл не создается.Я даже установил deleteIfEmpty = False.При отладке Writer 2 записи, которые пытается записать писатель, оба на 100% гидратированы, и Buffered Writer, кажется, пытается написать правильный XML.

batching-poc_1   | 2019-05-15 13:49:12.877  INFO 1 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [xmlFileToDataBaseStep]
batching-poc_1   | 2019-05-15 13:49:13.225  INFO 1 --- [           main] c.b.c.b.common.LoggingCustomerProcessor  : Processing customer:  68501
batching-poc_1   | 2019-05-15 13:49:13.225  INFO 1 --- [           main] c.b.c.b.common.LoggingCustomerProcessor  : Processing customer:  68502
batching-poc_1   | 2019-05-15 13:49:13.253  INFO 1 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [databaseToXmlFileStep]
batching-poc_1   | 2019-05-15 13:49:34.372  INFO 1 --- [           main] c.b.c.b.common.LoggingCustomerProcessor  : DB to XML: TESTCONTROL1000200
batching-poc_1   | 2019-05-15 13:49:34.372  INFO 1 --- [           main] c.b.c.b.common.LoggingCustomerProcessor  : DB to XML: TESTCONTROL1000201
batching-poc_1   | 2019-05-15 13:49:40.922  INFO 1 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=xmlFileToDatabaseJob]] completed with the following parameters: [{agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n, run.id=1}] and the following status: [COMPLETED]
batching-poc_1   | 2019-05-15 13:49:41.633  INFO 1 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Destroy method 'close' on bean with name 'databaseXmlItemWriter' threw an exception: java.lang.NullPointerException
batching-poc_1   | 2019-05-15 13:49:41.635  INFO 1 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Destroy method 'close' on bean with name 'databaseXmlItemReader' threw an exception: org.springframework.batch.item.ItemStreamException: Error while closing item reader
batching-poc_1   | 2019-05-15 13:49:41.636  INFO 1 --- [       Thread-3] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
batching-poc_1   | 2019-05-15 13:49:41.656  INFO 1 --- [       Thread-3] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
database.to.xml.job.export.file.path=/var/tmp/response/response.xml
The Above has Chmod 777 access

@Bean
    fun databaseXmlItemWriter(): StaxEventItemWriter<ControlInfo> {
        val xmlFileWriter = StaxEventItemWriter<ControlInfo>()

        val exportFilePath = environment.getRequiredProperty(PROPERTY_XML_EXPORT_FILE_PATH)
        xmlFileWriter.setResource(FileSystemResource(exportFilePath))

        xmlFileWriter.rootTagName = "ControlInfo"
        xmlFileWriter.setShouldDeleteIfEmpty(false)

        val studentMarshaller = Jaxb2Marshaller()
        studentMarshaller.setClassesToBeBound(ACDVRequest::class.java,ControlInfo::class.java)
        xmlFileWriter.setMarshaller(studentMarshaller)

        return xmlFileWriter
    }
batching-poc_1   | 2019-05-16 12:29:59.702 DEBUG 1 --- [           main] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
batching-poc_1   | 2019-05-16 12:29:59.768 DEBUG 1 --- [           main] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
batching-poc_1   | 2019-05-16 12:29:59.771 DEBUG 1 --- [           main] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
batching-poc_1   | 2019-05-16 12:29:59.841  INFO 1 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=xmlFileToDatabaseJob]] launched with the following parameters: [{agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n, run.id=1}]
batching-poc_1   | 2019-05-16 12:29:59.848 DEBUG 1 --- [           main] o.s.batch.core.job.AbstractJob           : Job execution starting: JobExecution: id=1, version=0, startTime=null, endTime=null, lastUpdated=Thu May 16 12:29:59 CDT 2019, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=1, version=0, Job=[xmlFileToDatabaseJob]], jobParameters=[{agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n, run.id=1}]
batching-poc_1   | 2019-05-16 12:29:59.865 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Resuming state=xmlFileToDatabaseJob.xmlFileToDataBaseStep with status=UNKNOWN
batching-poc_1   | 2019-05-16 12:29:59.865 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Handling state=xmlFileToDatabaseJob.xmlFileToDataBaseStep
batching-poc_1   | 2019-05-16 12:29:59.885  INFO 1 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [xmlFileToDataBaseStep]
batching-poc_1   | 2019-05-16 12:29:59.886 DEBUG 1 --- [           main] o.s.batch.core.step.AbstractStep         : Executing: id=1
batching-poc_1   | 2019-05-16 12:29:59.969 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Starting repeat context.
batching-poc_1   | 2019-05-16 12:29:59.970 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=1
batching-poc_1   | 2019-05-16 12:29:59.971 DEBUG 1 --- [           main] o.s.b.c.s.c.StepContextRepeatCallback    : Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@5c84624f
batching-poc_1   | 2019-05-16 12:29:59.971 DEBUG 1 --- [           main] o.s.b.c.s.c.StepContextRepeatCallback    : Chunk execution starting: queue size=0
batching-poc_1   | 2019-05-16 12:29:59.974 DEBUG 1 --- [           main] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
batching-poc_1   | 2019-05-16 12:29:59.980 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Starting repeat context.
batching-poc_1   | 2019-05-16 12:29:59.980 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=1
batching-poc_1   | 2019-05-16 12:30:00.228 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=2
batching-poc_1   | 2019-05-16 12:30:00.234 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=3
batching-poc_1   | 2019-05-16 12:30:00.235 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat is complete according to policy and result value.
batching-poc_1   | 2019-05-16 12:30:00.237  INFO 1 --- [           main] c.b.c.b.common.LoggingCustomerProcessor  : Processing customer:  68501
batching-poc_1   | 2019-05-16 12:30:00.237  INFO 1 --- [           main] c.b.c.b.common.LoggingCustomerProcessor  : Processing customer:  68502
batching-poc_1   | 2019-05-16 12:30:00.238 DEBUG 1 --- [           main] o.s.b.item.database.JdbcBatchItemWriter  : Executing batch with 2 items.
batching-poc_1   | 2019-05-16 12:30:00.246 DEBUG 1 --- [           main] o.s.b.c.step.item.ChunkOrientedTasklet   : Inputs not busy, ended: true
batching-poc_1   | 2019-05-16 12:30:00.247 DEBUG 1 --- [           main] o.s.batch.core.step.tasklet.TaskletStep  : Applying contribution: [StepContribution: read=2, written=2, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
batching-poc_1   | 2019-05-16 12:30:00.249 DEBUG 1 --- [           main] o.s.batch.core.step.tasklet.TaskletStep  : Saving step execution before commit: StepExecution: id=1, version=1, name=xmlFileToDataBaseStep, status=STARTED, exitStatus=EXECUTING, readCount=2, filterCount=0, writeCount=2 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=
batching-poc_1   | 2019-05-16 12:30:00.253 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat is complete according to policy and result value.
batching-poc_1   | 2019-05-16 12:30:00.253 DEBUG 1 --- [           main] o.s.batch.core.step.AbstractStep         : Step execution success: id=1
batching-poc_1   | 2019-05-16 12:30:00.260 DEBUG 1 --- [           main] o.s.batch.core.step.AbstractStep         : Step execution complete: StepExecution: id=1, version=3, name=xmlFileToDataBaseStep, status=COMPLETED, exitStatus=COMPLETED, readCount=2, filterCount=0, writeCount=2 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
batching-poc_1   | 2019-05-16 12:30:00.262 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Completed state=xmlFileToDatabaseJob.xmlFileToDataBaseStep with status=COMPLETED
batching-poc_1   | 2019-05-16 12:30:00.263 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Handling state=xmlFileToDatabaseJob.databaseToXmlFileStep
batching-poc_1   | 2019-05-16 12:30:00.278  INFO 1 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [databaseToXmlFileStep]
batching-poc_1   | 2019-05-16 12:30:00.278 DEBUG 1 --- [           main] o.s.batch.core.step.AbstractStep         : Executing: id=2
batching-poc_1   | 2019-05-16 12:30:01.784 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Starting repeat context.
batching-poc_1   | 2019-05-16 12:30:01.784 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=1
batching-poc_1   | 2019-05-16 12:30:01.785 DEBUG 1 --- [           main] o.s.b.c.s.c.StepContextRepeatCallback    : Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext@aed0151
batching-poc_1   | 2019-05-16 12:30:01.785 DEBUG 1 --- [           main] o.s.b.c.s.c.StepContextRepeatCallback    : Chunk execution starting: queue size=0
batching-poc_1   | 2019-05-16 12:30:01.786 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Starting repeat context.
batching-poc_1   | 2019-05-16 12:30:01.786 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=1
batching-poc_1   | 2019-05-16 12:30:01.824 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=2
batching-poc_1   | 2019-05-16 12:30:01.825 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat operation about to start at count=3
batching-poc_1   | 2019-05-16 12:30:01.825 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat is complete according to policy and result value.
batching-poc_1   | 2019-05-16 12:30:01.826  INFO 1 --- [           main] c.b.c.b.common.DbToXmlProcessor         : DB to XML: TESTCONTROL1000200
batching-poc_1   | 2019-05-16 12:30:01.826  INFO 1 --- [           main] c.b.c.b.common.DbToXmlProcessor         : DB to XML: TESTCONTROL1000201
batching-poc_1   | 2019-05-16 12:30:01.958 DEBUG 1 --- [           main] o.s.b.c.step.item.ChunkOrientedTasklet   : Inputs not busy, ended: true
batching-poc_1   | 2019-05-16 12:30:01.958 DEBUG 1 --- [           main] o.s.batch.core.step.tasklet.TaskletStep  : Applying contribution: [StepContribution: read=2, written=2, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
batching-poc_1   | 2019-05-16 12:30:01.960 DEBUG 1 --- [           main] o.s.batch.core.step.tasklet.TaskletStep  : Saving step execution before commit: StepExecution: id=2, version=1, name=databaseToXmlFileStep, status=STARTED, exitStatus=EXECUTING, readCount=2, filterCount=0, writeCount=2 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=
batching-poc_1   | 2019-05-16 12:30:01.965 DEBUG 1 --- [           main] o.s.batch.repeat.support.RepeatTemplate  : Repeat is complete according to policy and result value.
batching-poc_1   | 2019-05-16 12:30:01.965 DEBUG 1 --- [           main] o.s.batch.core.step.AbstractStep         : Step execution success: id=2
batching-poc_1   | 2019-05-16 12:30:03.062 DEBUG 1 --- [           main] o.s.batch.core.step.AbstractStep         : Step execution complete: StepExecution: id=2, version=3, name=databaseToXmlFileStep, status=COMPLETED, exitStatus=COMPLETED, readCount=2, filterCount=0, writeCount=2 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
batching-poc_1   | 2019-05-16 12:30:03.066 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Completed state=xmlFileToDatabaseJob.databaseToXmlFileStep with status=COMPLETED
batching-poc_1   | 2019-05-16 12:30:03.066 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Handling state=xmlFileToDatabaseJob.COMPLETED
batching-poc_1   | 2019-05-16 12:30:03.066 DEBUG 1 --- [           main] o.s.b.core.job.flow.support.SimpleFlow   : Completed state=xmlFileToDatabaseJob.COMPLETED with status=COMPLETED
batching-poc_1   | 2019-05-16 12:30:03.069 DEBUG 1 --- [           main] o.s.batch.core.job.AbstractJob           : Job execution complete: JobExecution: id=1, version=1, startTime=Thu May 16 12:29:59 CDT 2019, endTime=null, lastUpdated=Thu May 16 12:29:59 CDT 2019, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=1, version=0, Job=[xmlFileToDatabaseJob]], jobParameters=[{agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n, run.id=1}]
batching-poc_1   | 2019-05-16 12:30:03.073  INFO 1 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=xmlFileToDatabaseJob]] completed with the following parameters: [{agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n, run.id=1}] and the following status: [COMPLETED]
batching-poc_1   | 2019-05-16 12:30:03.647  INFO 1 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Destroy method 'close' on bean with name 'databaseXmlItemWriter' threw an exception: java.lang.NullPointerException
batching-poc_1   | 2019-05-16 12:30:03.649  INFO 1 --- [       Thread-3] o.s.b.f.support.DisposableBeanAdapter    : Destroy method 'close' on bean with name 'databaseXmlItemReader' threw an exception: org.springframework.batch.item.ItemStreamException: Error while closing item reader
batching-poc_1   | 2019-05-16 12:30:03.652  INFO 1 --- [       Thread-3] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
batching-poc_1   | 2019-05-16 12:30:03.664  INFO 1 --- [       Thread-3] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
batching-poc_batching-poc_1 exited with code 0


  @Bean
    fun xmlFileToDatabaseJob(jobBuilderFactory: JobBuilderFactory, @Qualifier("databaseToXmlFileStep") dbToXmlStep: Step, @Qualifier("xmlFileToDataBaseStep") xmlCustomerStep: Step): Job {

        return jobBuilderFactory.get("xmlFileToDatabaseJob")
                .incrementer(RunIdIncrementer())
                .flow(xmlCustomerStep)
                .next(dbToXmlConfig.databaseToXmlFileStep())
                .end()
                .build()
    }

...