0

I would like to add a Spring Batch module to Java 1.8, Maven 3.3.3 project for running batch jobs.

The module(s) should be a Maven child

of this parent:

<parent>
        <artifactId>portfolio-service-parent</artifactId>
        <groupId>com.distributedfinance</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

At the moment I have three separate batch jobs. Is it better to organize all the batch jobs into one XML config file? Have three distinct modules each with it's own config file? One module with three distinct config files?

Thanks!

Here's the config file for the complex job:

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

    <bean name="jobParametersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>

    <!-- BATCH-2351 workaround -->
    <bean id="stepScope" class="org.springframework.batch.core.scope.StepScope">
        <property name="autoProxy" value="true"/>
    </bean>

    <batch:job id="baiParseJob" incrementer="jobParametersIncrementer">
        <batch:step id="baiParseStep" next="baiArchive">
            <batch:tasklet transaction-manager="transactionManager">
                <batch:chunk reader="baiItemReader"
                             processor="baiItemProcessor"
                             writer="baiItemWriter"
                             commit-interval="1"/>
            </batch:tasklet>
        </batch:step>
        <batch:step id="baiArchive">
            <batch:tasklet ref="fileArchivingTasklet"/>
        </batch:step>
    </batch:job>

    <bean id="baiItemReader" class="com.distributedfinance.mbi.bai.reader.MultiLineBaiItemReader"
            scope="step">
        <property name="delegate" ref="flatFileItemReader"/>
        <property name="baiFileFieldSetMapper">
            <bean class="com.distributedfinance.mbi.bai.mapper.BaiFileFieldSetMapper"/>
        </property>
        <property name="baiGroupFieldSetMapper">
            <bean class="com.distributedfinance.mbi.bai.mapper.BaiGroupFieldSetMapper"/>
        </property>
        <property name="baiAccountFieldSetMapper">
            <bean class="com.distributedfinance.mbi.bai.mapper.BaiAccountFieldSetMapper">
                <property name="parser">
                    <bean class="com.distributedfinance.mbi.bai.mapper.BaiTypeParser"/>
                </property>
            </bean>
        </property>
        <property name="baiTransactionFieldSetMapper">
            <bean class="com.distributedfinance.mbi.bai.mapper.BaiTransactionFieldSetMapper"/>
        </property>
    </bean>

    <bean id="flatFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
        <property name="resource" value="#{jobParameters['input.file.url']}"/>
        <property name="lineMapper">
            <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
                <property name="lineTokenizer">
                    <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"/>
                </property>
                <property name="fieldSetMapper">
                    <bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper"/>
                </property>
            </bean>
        </property>
    </bean>

    <bean id="baiItemProcessor" class="com.distributedfinance.mbi.bai.processor.BaiItemProcessor">
        <constructor-arg index="0" ref="accountLookup"/>
        <constructor-arg index="1">
            <bean class="java.text.SimpleDateFormat">
                <constructor-arg value="yyMMddHHmmss"/>
            </bean>
        </constructor-arg>
    </bean>

    <bean id="baiItemWriter" class="com.distributedfinance.mbi.bai.writer.BaiItemWriter"/>

    <bean id="accountLookup" class="com.distributedfinance.mbi.bai.lookup.AccountLookup"/>

    <bean id="fileArchivingTasklet" class="com.distributedfinance.mbi.bai.tasklet.FileArchivingTasklet">
        <property name="downloadFileKey" value="input.file.url"/>
        <property name="archiveDirectory" value="${bai.sftp.archive-dir}"/>
        <property name="purgeDays" value="${bai.sftp.purge-days}"/>
    </bean>
 </beans>

enter image description here

dbl001
  • 2,259
  • 8
  • 39
  • 53
  • Although your job seems complex, I think it's not too complex to keep in a single file. Keeping it in the same file means it is easier to read. If you have other jobs with similar complexity, then maybe you should put each job in a separate config file and have a "master" config referring to the individual job config files. Regardless of their complexity, you may want ot put each job in separate config file anyway if they belong to different logical domains – Taoufik Mohdit Feb 08 '16 at 10:35
  • In your opinion - what are the trade-offs between putting the configuration for each job in one/many XML files -vs- putting all the config in one Java file (like in this example: https://spring.io/guides/gs/batch-processing?) – dbl001 Feb 08 '16 at 16:40
  • Sorry I can't comment on that, as I am not very familiar with Java Config approach – Taoufik Mohdit Feb 08 '16 at 17:06
  • Ok. Do you know of any examples with multiple config files called by one 'master' config file? – dbl001 Feb 08 '16 at 17:37
  • In XML configuration, this can be achieved using `import`. See http://stackoverflow.com/questions/5113579/how-to-import-spring-config-xml-of-one-project-into-spring-config-xml-of-another – Taoufik Mohdit Feb 08 '16 at 17:43

0 Answers0