geira
Feb 20th, 2008, 02:28 PM
Where in the batch-job should we implement code/functionality for logging to database successfull process/failure of a job?
I enclose the job-config we use
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<description>This job imports payments from the accounting system</description>
<import resource="classpath:/springAccountBalancerCore-configurer.xml"/>
<import resource="classpath:/springAccountBalancerCore-dao.xml"/>
<bean id="simpleJob"
class="org.springframework.batch.core.configuration.JobCo nfiguration"
abstract="true">
<property name="restartable" value="false" />
<property name="startLimit" value="-1"/>
</bean>
<bean parent="stepScope" />
<bean parent="jobConfigurationRegistryBeanPostProcessor" />
<bean id="paymentImportJob" parent="simpleJob">
<property name="steps">
<bean id="step1"
class="org.springframework.batch.execution.step.RepeatOpe rationsStepConfiguration">
<property name="tasklet">
<bean class="org.springframework.batch.execution.tasklet.Restar tableItemProviderTasklet">
<property name="itemProvider">
<bean class="org.springframework.batch.item.provider.InputSourc eItemProvider">
<property name="inputSource" ref="fileInputSource" />
</bean>
</property>
<property name="itemProcessor">
<bean
class="no.aftenposten.accountbalancer.batch.processor.Pay mentImportLineProcessor">
<property name="outputSource" ref="invoiceManagerOutputSource" />
<property name="invoicingManager" ref="invoicingManager"/>
</bean>
</property>
</bean>
</property>
<property name="chunkOperations">
<bean class="org.springframework.batch.repeat.support.RepeatTem plate">
<property name="interceptors" ref="invoiceManagerOutputSource" />
<property name="completionPolicy">
<bean class="org.springframework.batch.repeat.policy.SimpleComp letionPolicy">
<property name="chunkSize" value="1" />
</bean>
</property>
</bean>
</property>
<property name="stepOperations">
<bean class="org.springframework.batch.repeat.support.RepeatTem plate">
<property name="exceptionHandler">
<bean class="org.springframework.batch.repeat.exception.handler .SimpleLimitExceptionHandler"
p:limit="0" p:useParent="true" p:type="java.lang.Exception" />
</property>
</bean>
</property>
</bean>
</property>
</bean>
<!-- This is a framework class that needs a delegate and also needs to be registered as a RepeatInterceptor in the chunk -->
<bean id="invoiceManagerOutputSource"
class="no.aftenposten.accountbalancer.batch.outputsource. InvoicingManagerOutputSource" >
<property name="invoicingDao" ref="invoicingJdbcDao"/>
</bean>
<bean id="paymentLineMapper" class="no.aftenposten.accountbalancer.batch.mapper.Paymen tFieldSetMapper" />
<bean id="paymentLineDescriptor"
class="org.springframework.batch.io.file.support.transfor m.DelimitedLineTokenizer">
<property name="delimiter" value=";"/>
</bean>
<bean id="fileInputSource" class="org.springframework.batch.io.file.support.DefaultF latFileInputSource">
<property name="resource"
value="classpath:paymentInput.txt" />
<property name="tokenizer" ref="paymentLineDescriptor" />
<property name="fieldSetMapper" ref="paymentLineMapper" />
</bean>
<bean parent="customEditorConfigurer" />
</beans>
I enclose the job-config we use
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<description>This job imports payments from the accounting system</description>
<import resource="classpath:/springAccountBalancerCore-configurer.xml"/>
<import resource="classpath:/springAccountBalancerCore-dao.xml"/>
<bean id="simpleJob"
class="org.springframework.batch.core.configuration.JobCo nfiguration"
abstract="true">
<property name="restartable" value="false" />
<property name="startLimit" value="-1"/>
</bean>
<bean parent="stepScope" />
<bean parent="jobConfigurationRegistryBeanPostProcessor" />
<bean id="paymentImportJob" parent="simpleJob">
<property name="steps">
<bean id="step1"
class="org.springframework.batch.execution.step.RepeatOpe rationsStepConfiguration">
<property name="tasklet">
<bean class="org.springframework.batch.execution.tasklet.Restar tableItemProviderTasklet">
<property name="itemProvider">
<bean class="org.springframework.batch.item.provider.InputSourc eItemProvider">
<property name="inputSource" ref="fileInputSource" />
</bean>
</property>
<property name="itemProcessor">
<bean
class="no.aftenposten.accountbalancer.batch.processor.Pay mentImportLineProcessor">
<property name="outputSource" ref="invoiceManagerOutputSource" />
<property name="invoicingManager" ref="invoicingManager"/>
</bean>
</property>
</bean>
</property>
<property name="chunkOperations">
<bean class="org.springframework.batch.repeat.support.RepeatTem plate">
<property name="interceptors" ref="invoiceManagerOutputSource" />
<property name="completionPolicy">
<bean class="org.springframework.batch.repeat.policy.SimpleComp letionPolicy">
<property name="chunkSize" value="1" />
</bean>
</property>
</bean>
</property>
<property name="stepOperations">
<bean class="org.springframework.batch.repeat.support.RepeatTem plate">
<property name="exceptionHandler">
<bean class="org.springframework.batch.repeat.exception.handler .SimpleLimitExceptionHandler"
p:limit="0" p:useParent="true" p:type="java.lang.Exception" />
</property>
</bean>
</property>
</bean>
</property>
</bean>
<!-- This is a framework class that needs a delegate and also needs to be registered as a RepeatInterceptor in the chunk -->
<bean id="invoiceManagerOutputSource"
class="no.aftenposten.accountbalancer.batch.outputsource. InvoicingManagerOutputSource" >
<property name="invoicingDao" ref="invoicingJdbcDao"/>
</bean>
<bean id="paymentLineMapper" class="no.aftenposten.accountbalancer.batch.mapper.Paymen tFieldSetMapper" />
<bean id="paymentLineDescriptor"
class="org.springframework.batch.io.file.support.transfor m.DelimitedLineTokenizer">
<property name="delimiter" value=";"/>
</bean>
<bean id="fileInputSource" class="org.springframework.batch.io.file.support.DefaultF latFileInputSource">
<property name="resource"
value="classpath:paymentInput.txt" />
<property name="tokenizer" ref="paymentLineDescriptor" />
<property name="fieldSetMapper" ref="paymentLineMapper" />
</bean>
<bean parent="customEditorConfigurer" />
</beans>