1
我使用org.springframework.batch.item.database.JdbcBatchItemWriter
將文件寫入數據庫並使用org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper
來映射列。數據沒有被插入到數據庫中,也沒有在日誌中發現任何錯誤。無法使用彈簧批量將數據加載到MySQL DB
<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>>
我測試了你的配置(從你的XML樣本),它實際上是在數據庫中插入記錄。你在用什麼DMBS?你可以發佈'dataSource' bean(沒有用戶/密碼)嗎?你的依賴關係中是否有正確的驅動程序? – Thrax
它的我的SQL數據庫,我能夠使用「org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper」與同一個作家插入數據,所以希望不會有任何數據源或連接問題。 「com.microsoft.sqlserver.jdbc.SQLServerDriver」是驅動程序。 – Amuthan
爲了使它與MySQL DBMS一起工作,我使用了'com.mysql.jdbc.Driver',依賴關係是:' mysql mysql-connector-java '。 –
Thrax