Announcement Announcement Module
Collapse
No announcement yet.
why cant use jobExecutionListeners within a <job..> element Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • why cant use jobExecutionListeners within a <job..> element

    I've got a top level job that runs a number of steps like this:

    Code:
    <job id="feedEventJob" xmlns="http://www.springframework.org/schema/batch" parent="simpleJob">
    		
    	<step id="processFeedEventStep" parent="simpleStep">
    		<tasklet>
    			<chunk reader="feedEventItemReader" 
    				writer="feedEventItemWriter" 
    				commit-interval="${job.commit.interval}"/>
    			<listeners><listener ref="feedEventItemReader"/></listeners>
    		</tasklet>
    		<next on="completed" to="batchRoundStep"/>
    	</step>
    
        
            <step id="batchRoundStep">
            	<tasklet ref="processValuations"/>
            </step> 
    </job>
    and what i want to do is add a JobExecutionListeners property into the above

    Code:
            <property name="jobExecutionListeners">
                <list>
                    <bean class="com.feedsubs.utils.JobExecutionStatusLogger"/>
                </list>
            </property>
    The JobExecutionStatusLogger class is just a logging class that logs when the job finishes/starts etc..

    but spring batch xml doesnt seem to like that property within a <job..> element.. can someone help me out? thanks.

    It doesn't seem to like this:
    Code:
    <job id="feedEventJob" xmlns="http://www.springframework.org/schema/batch" parent="simpleJob">
    		
    	<step id="processFeedEventStep" parent="simpleStep">
    		<tasklet>
    			<chunk reader="feedEventItemReader" 
    				writer="feedEventItemWriter" 
    				commit-interval="${job.commit.interval}"/>
    			<listeners><listener ref="feedEventItemReader"/></listeners>
    		</tasklet>
    		<next on="completed" to="batchRoundStep"/>
    	</step>
    
        
            <step id="batchRoundStep">
            	<tasklet ref="processValuations"/>
            </step> 
    
            <property name="jobExecutionListeners">
                <list>
                    <bean class="com.feedsubs.utils.JobExecutionStatusLogger"/>
                </list>
            </property>
    </job>

  • #2
    replace

    Code:
    <job id="feedEventJob" xmlns="http://www.springframework.org/schema/batch" parent="simpleJob">
    		
    	<step id="processFeedEventStep" parent="simpleStep">
    		<tasklet>
    			<chunk reader="feedEventItemReader" 
    				writer="feedEventItemWriter" 
    				commit-interval="${job.commit.interval}"/>
    			<listeners><listener ref="feedEventItemReader"/></listeners>
    		</tasklet>
    		<next on="completed" to="batchRoundStep"/>
    	</step>
    
        
            <step id="batchRoundStep">
            	<tasklet ref="processValuations"/>
            </step> 
    
            <property name="jobExecutionListeners">
                <list>
                    <bean class="com.feedsubs.utils.JobExecutionStatusLogger"/>
                </list>
            </property>
    </job>
    with

    Code:
    <batch:job id="feedEventJob" parent="simpleJob">	
            <batch:step id="processFeedEventStep" parent="simpleStep">
    	<batch:tasklet>
    	        <batch:chunk reader="feedEventItemReader" writer="feedEventItemWriter" 
    				commit-interval="${job.commit.interval}"/>
    	        <batch:listeners><batch:listener ref="feedEventItemReader"/></batch:listeners>
    	</batch:tasklet>
    	<batch:next on="completed" to="batchRoundStep"/>
            </batch:step>
            <batch:step id="batchRoundStep">
            	<batch:tasklet ref="processValuations"/>
            </batch:step> 
    
            <batch:listeners>
    	<batch:listener>
    		<bean class="com.feedsubs.utils.JobExecutionStatusLogger"></bean>
    	</batch:listener>
            </batch:listeners>
    </batch:job>
    I recommend you to create namespace batch for spring-batch if you want to mix both normal beans schema and batch schema
    in the same configuration file

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd>

    Comment

    Working...
    X