我正在使用org.springframework.batch.item.database.JdbcBatchItemWriter
将文件写入数据库并使用org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper
映射列。数据没有插入到数据库中,也没有在日志中出现任何错误。
<bean id="ItemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
insert into Student_Details(Name,Id,ClassId,Rank) values (:Name, :Id, :ClassId, :Rank)
]]>
</value>
</property>
<property name="itemSqlParameterSourceProvider">
<bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
2016-04-28 05:45:59,904 INFO [com.sam.test.mine.scheduler.SchedulerService] [fileFirmsChannelPool-2] INFO - <Ok file received: Student_details_20160116.OK>
Apr 28, 2016 5:45:59 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=StudentDetailsJob]] launched with the following parameters: [{groupId=0, size=0,filename=file:/app/data/Student_details_20160116.txt, filenames=file:/app/data/Student_details_20160116.txt, now=1461836759909,type=STUDENT_DET}]
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: Executing step: [cleanStudentDetails]
2016-04-28 05:46:00,362 INFO [com.sam.test.mine.batch.JdbcUpdateTasklet] [fileFirmsChannelPool-2] INFO - <Deleted table Student_Details successfully.>
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: Executing step: [studentDetailsStep]
Apr 28, 2016 5:46:00 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
Apr 28, 2016 5:46:00 AM org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: Executing step: [archiveStudentDetails]
2016-04-28 05:46:00,894 INFO [com.sam.test.mine.batch.FileArchiverTasklet] [fileFirmsChannelPool-2] INFO - <Archiving ... >
2016-04-28 05:46:00,902 INFO [com.sam.test.mine.batch.FileArchiverTasklet] [fileFirmsChannelPool-2] INFO - <success moving file to archive: /app/data/Student_details_20160116.txt to /app/archive/20160428/Student_details_20160116.txt.execution#33912>
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run
INFO: Job: [FlowJob: [name=StudentDetailsJob]] completed with the following parameters: [{groupId=0, size=0, filename=file:/app/data/Student_details_20160116.txt, filenames=file:/app/data/Student_details_20160116.txt, now=1461836759909, type=STUDENT_DET}] and the following status: [COMPLETED]
2016-04-28 05:46:00,975 INFO [com.sam.test.mine.scheduler.SchedulerService] [fileFirmsChannelPool-2] INFO - <finish deleting Ok file /app/data/Student_details_20160116.OK>>
答案 0 :(得分:0)
我在BATCH_STEP_EXECUTION表中看到READ_COUNT个值,但WRITE_COUNT为0,WRITE_SKIP_COUNT与读取计数相同。
-Amuthan
当您的READ_COUNT
与您的WRITE_SKIP_COUNT
匹配时,它意味着您的JdbcBatchItemWriter
中已抛出异常,该异常已在skippable-exception-classes
属性中注册为可跳过的异常。< / p>
<step id="step1">
<tasklet>
<chunk reader="soemReader" writer="jdbcWriter"
commit-interval="10" skip-limit="10">
<skippable-exception-classes>
<include class="com.package.YourException"/>
</skippable-exception-classes>
</chunk>
</tasklet>
</step>
我删除任何可跳过的例外,除非您有真正的业务来吞下这样的错误。