Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Use parameters in job.xml using %%

  1. #1

    Default Use parameters in job.xml using %%

    Hi,
    I use m5 version of spring batch .
    I run my batch jobs with the parameters : /monjob.xml monjob batch.scheduleDate=200803111000.

    In my job.xml file, I would like to use the batch.scheduleDate value in the name of an output file.
    For that, I have replaced ${batch.scheduleDate} in the name of the ouputFile (in m3 version) by %batch.scheduleDate% but it doesn't work.
    Here is my job.xml file.
    <?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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    <import resource="classpath:simple-container-definition.xml" />

    <bean id="ExtractionClientsJob" parent="simpleJob">
    <property name="steps">
    <list>
    <bean id="Extraction" parent="simpleStep">
    <property name="streams" ref="clientFileWriter"/>
    <property name="commitInterval" value="2" />
    <property name="allowStartIfComplete" value="false" />
    <property name="itemReader" ref="DbItemReader" />
    <property name="itemWriter" ref="clientFileWriter"/>
    </bean>
    </list>
    </property>
    </bean>

    <!-- INFRASTRUCTURE SETUP -->
    <bean id="DbItemReader" class="com.natixis.sphinx.batch.reader.DbItemReade r">
    <property name="dataSource" ref="dataSource" />
    <property name="sql">
    <value> select p.ceseqo, p.cocivi,p.nompat,p.nommar,p.prenom,p.preno2,p.dah eme,p.cosecu,p.cositf,a.librue,a.copost,a.libvil,a .copays,a.coposn,a.copayn,a.libvin,c.cochar,c.dahe m1,c.numrib from sphmclient c, sphmadresse a, sphmpersonne p where c.cochar=7 and c.copers=p.ceseqo and p.ceseqo=a.copers order by p.ceseqo</value>
    </property>
    <property name="mapper">
    <bean class="com.natixis.sphinx.batch.modele.mapping.Cli entRowMapper" />
    </property>
    </bean>

    <bean id="clientFileWriter" class="org.springframework.batch.io.file.FlatFileI temWriter">
    <property name="resource" ref="resourceSortie1" />
    <property name="lineAggregator" >
    <bean class="org.springframework.batch.io.file.transform .DelimitedLineAggregator">
    <property name="delimiter" value=";"/>
    </bean>
    </property>
    <property name="fieldSetUnmapper" >
    <bean class="com.natixis.sphinx.batch.modele.mapping.Cli entFieldSetCreator" />
    </property>
    <property name="shouldDeleteIfExists" value="true"/>
    </bean>

    <bean id="mapContext" class="com.natixis.sphinx.batch.domain.Context">
    <property name="map">
    <map>
    <entry key="resourceSortie1" value-ref="resourceSortie1"/>
    <entry key="dataSource" value-ref="dataSource"/>
    </map>
    </property>
    </bean>


    <bean id="resourceSortie1" class="java.lang.String">
    <constructor-arg value="file:data/output/%batch.scheduleDate%.clients.txt"/>
    </bean>

    </beans>
    I have read that the class org.springframework.batch.execution.resource.StepE xecutionProxyResource replace %% by the value of parameters but I don't know what I have to do to be able to use it.

    Could you give me a sample which shows how to use parameters of batch in job.xml?

    Thanks in advance (sorry for my bad english).

  2. #2

    Default

    I think you mean
    Code:
    %{batch.scheduleDate}

  3. #3

    Default

    I have tried:
    %{batch.scheduleDate}
    and
    %{batch.scheduleDate}%

    but it isn't replaced by the value.

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    You need to use the actual StepExecutionResourceProxy, you're just creating a String. It should look something like:

    Code:
    <bean id="resourceSortie1" class="org.springframework.batch.core.support.StepExecutionResourceProxy">
      <property name="filePattern" value="data/output/%batch.scheduleDate%.clients.txt" />
    </bean>
    I haven't checked that to ensure it's valid, but I think you get the idea. The spring container won't automatically convert your string using the proxy, you have to declare it directly.

  5. #5
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I almost forget, you need to register the proxy with the step as well, so that it can get access to the job parameters.

  6. #6

    Default

    Thanks for your answers.

    I tried the following job.xml:
    <bean id="ExtractionClientsJob" parent="simpleJob">
    <property name="steps">
    <list>
    <bean id="Extraction" parent="simpleStep">
    <property name="listeners" ref="resourceSortie1"/> <property name="commitInterval" value="2" />
    <property name="allowStartIfComplete" value="false" />
    <property name="itemReader" ref="DBInputTemplate" />
    <property name="itemWriter" ref="clientFileWriter"/>

    </bean>
    </list>
    </property>
    </bean>
    ...
    <bean id="resourceSortie1" class="org.springframework.batch.execution.resource.StepE xecutionProxyResource">
    <property name="filePattern" value="data/output/%batch.scheduleDate%.clients.txt"/> </bean>
    But the error is always:
    The delegate resource has not been initialised. Remember to register this object as a StepListener.
    And I don't understand how to register this object as a StepListener.
    Could you clarify this point please?

  7. #7
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    You have registered the listener in the fragement you showed. Maybe we are missing something else? From the stack trace you can probably see where the resource is being used - my guess it is being used outside the step somewhere?

  8. #8

    Default

    Yes it's used by clientFileWriter which is a FlatFileItemWriter:
    <bean id="clientFileWriter" class="org.springframework.batch.io.file.FlatFileI temWriter">
    <property name="resource" ref="resourceSortie1"/>
    <property name="lineAggregator" >
    <bean class="org.springframework.batch.io.file.transform .DelimitedLineAggregator">
    <property name="delimiter" value=";"/>
    </bean>
    </property>
    <property name="fieldSetUnmapper" >
    <bean class="com.natixis.sphinx.batch.modele.mapping.Cli entFieldSetCreator" />
    </property>
    <property name="shouldDeleteIfExists" value="true"/>
    </bean>
    But a flatFileItemWriter isn't a stepListener and can't register stepListener. Then I don't know what I must do.

  9. #9
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    You need to register the proxy as a StepListener, separate from the writer.

  10. #10

    Default

    Sorry but I don't understand the code I must write to register the proxy.

    Could you give me the code I must write in my job.xml or explain what I must do exactly (perhaps code in job.xml is good and I must create a itemReader class which implements ItemReadListener and then use my itemReader class instead of FlatFileItemReader)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •