Thursday, April 23, 2015

Spring Batch- Creating Job Repository,Job Launcher Configuration - With DB

12:59 PM - By Manu 0

In this post we will discuss job repository configuration.
If you application data source(schema) is different from spring batch data source you need to create two data sources one for application and the other for spring batch

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util" xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"
default-lazy-init="true">


<!-- ************************************************************************************************************** -->
<!-- * To work with Spring Batch We need a job repository, this job repository
is used to store the spring batch job meta meta data information such as
who is launched the job with which parameters job got launched etc etc following
Configuration explains the job repository configuration -->
<!-- ************************************************************************************************************** -->

<batch:job id="simpleJob" incrementer="jobIncrementor"
job-repository="jobRepository" restartable="true" abstract="true">
<batch:listeners>
<batch:listener ref="listener"></batch:listener>
</batch:listeners>
</batch:job>


<bean id="listener" class="com.springbatchdemo.parallel.JobProcessTimeListener" />
//Below configuration for job incrementor
<!--<bean id="jobIncrementor" class="com.springbatchdemo.incrementor.JobIncrementor" />-->

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

<!-- Job Repository configuration this is important and must -->
<batch:job-repository id="jobRepository"
data-source="jdbc.dataSource" transaction-manager="batch.transactionManager"
max-varchar-length="2500" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="jdbc.dataSource" />
</bean>
<bean id="batch.transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="jdbc.dataSource" />
</bean>

<!-- ********************************************************************************************************** -->
<!-- Data Source Configuration -->
<!-- ********************************************************************************************************** -->
<bean id="jdbc.dataSource" class="com.ibm.db2.jcc.DB2SimpleDataSource">
<property name="driverType" value="4" />
<property name="serverName" value="${jdbc.host}" />
<property name="portNumber" value="${jdbc.port}" />
<property name="databaseName" value="${jdbc.dbName}" />
<property name="currentSchema" value="DB SCHEMA" />
<property name="user" value="${jdbc.userName}" />
<property name="password" value="${jdbc.password}" />
<property name="resultSetHoldability" value="1" />
<property name="clientApplicationInformation" value="Test" />
<property name="clientProgramName" value="Test :SpringBatch" />
<property name="clientUser" value="XXX" />
</bean>

<!-- Jdbc Template Configuration -->
<bean id="jdbc.template" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="jdbc.dataSource" />
</bean>


</beans>

The values in bold can be used for db tracking

Share This Post

0 comments:

Feel Free to Share your Feeling about these content

© 2014 GSDUNIA. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top