1. 程式人生 > >跑批利器--往資料庫裡配置SpringBatch

跑批利器--往資料庫裡配置SpringBatch

      Spring Batch提供一個任務的倉庫實現將你的任務元資料儲存在資料庫中,這樣的話你就可以監控你的批量處理程序以及他們的結果.

       Spring Batch 資料庫引擎支援的有:DB2,Derby, H2, HSQLDB,

MySQL, Oracle, PostgreSQL, SQLServer, and Sybase.你所需要做的就是為SpringBatch建立一個數據庫並執行正確的SQL指令碼.

接下來的程式碼例項將是展示如何配置JobRepository到資料庫中.

<?xmlversion="1.0" encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:batch="http://www.springframework.org/schema/batch"

xsi:schemaLocation="http://www.springframework.org/schema/beans

<batch:job-repositoryid="jobRepository"

data-source="dataSource"transaction-manager="transactionManager" />

<beanid="jobLauncher"

class="org.springframework.batch.core.launch.support.SimpleJobLauncher">

<propertyname="jobRepository" ref="jobRepository" />

</bean>

<beanid="dataSource"

class="org.springframework.jdbc.datasource.SingleConnectionDataSource">

<propertyname="driverClassName" value="org.h2.Driver" />

<propertyname="url" value=" jdbc:h2:mem:sbia_ch02;DB_CLOSE_DELAY=-1"/>

<propertyname="username" value="sa" />

<propertyname="password" value="" />

<propertyname="suppressClose" value="true" />

</bean>

<beanid="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<propertyname="dataSource" ref="dataSource" />

</bean>

</beans>

上述示例中,Job-Repository xml元素在batch的名稱空間下建立一個jobRepository.為了能夠正確執行,這個任務倉庫需要一個數據源和事務管理器的支援.主要是配置這三項內容.