Daily Archives: July 2, 2015

Springbatch transaction manager

In SpringBatch, we can set transacational commit. This is very useful and important in batch job. Batch job won’t commit until a whole chunk process is done. Important part is that we should use DataSourceTransactionManager instead ofResourcelessTransactionManager.

Below is the configuration supporting transaction commit in SpringBatch.

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">

   <import resource="database.xml"/>

   <!-- stored job-meta in memory -->
   <bean id="jobRepository"
      class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
      <property name="transactionManager" ref="transactionManager" />
   </bean>

   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
      <property name="dataSource" ref="dataSource"/>
   </bean>

   <bean id="jobLauncher"
      class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
      <property name="jobRepository" ref="jobRepository" />
   </bean>

</beans>