0

I have an XML-configured step, and I wanted to add the batch:next elements in order to get conditional flowing in my job :

    <batch:step id="stepLoadCashFlows">
        <batch:next on="*" to="stepCleanOldTrades" />
        <batch:next on="FAILED" to="stepCleanCurrentTradesOnError" />
        <batch:tasklet>
            <batch:chunk reader="cashFlowItemReader" writer="cashFlowItemWriter"
                processor="cashFlowsProcessor" commit-interval="10000" skip-limit="${cds.skip.limit}">
                <batch:skippable-exception-classes>
                    <batch:include class="org.springframework.integration.transformer.MessageTransformationException" />
                </batch:skippable-exception-classes>
            </batch:chunk>
        </batch:tasklet>
        <listeners>
            <listener ref="cashFlowWriterListener" />
        </listeners>
    </batch:step>

This gets me the following error :

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:cpm-batch-main-cds-load.xml]
Offending resource: class path resource [cpm-dml-subscriber-cds-top-level.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 80 in XML document from class path resource [cpm-batch-main-cds-load.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 80; columnNumber: 19; cvc-complex-type.2.4.a : Invalid content found starting with element 'batch:tasklet'. One of the following values '{"http://www.springframework.org/schema/batch":next, "http://www.springframework.org/schema/batch":stop, "http://www.springframework.org/schema/batch":end, "http://www.springframework.org/schema/batch":fail, "http://www.springframework.org/schema/batch":listeners}' is expected.

So where should I put these (I've tried at the end of step, inside tasklet...) ?

l0r3nz4cc10
  • 1,237
  • 6
  • 27
  • 50

1 Answers1

1

transitions elements should be put after the tasklet element. So in your case the following should work:

<batch:step id="stepLoadCashFlows">
    <batch:tasklet>
        <batch:chunk reader="cashFlowItemReader" writer="cashFlowItemWriter"
            processor="cashFlowsProcessor" commit-interval="10000" skip-limit="${cds.skip.limit}">
            <batch:skippable-exception-classes>
                <batch:include class="org.springframework.integration.transformer.MessageTransformationException" />
            </batch:skippable-exception-classes>
        </batch:chunk>
        <batch:listeners>
           <batch:listener ref="cashFlowWriterListener" />
        </batch:listeners>
    </batch:tasklet>
    <batch:next on="*" to="stepCleanOldTrades" />
    <batch:next on="FAILED" to="stepCleanCurrentTradesOnError" />
</batch:step>

Note that the listeners element should be inside the tasklet element.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50