当我运行 spring 批处理作业时,chunkListener 不运行

我在 springBatch 作业中使用 checkListener 和 readListener 作为我用来学习 springbatch 的示例。但是当我运行作业时,chunkListener 不运行,只有 readListener 与作业一起运行。


personChunkListener.java:




     package sb.dbToxml;


        import javax.batch.api.chunk.listener.ChunkListener;


        public class PersonChunkListener implements ChunkListener

        {


          @Override

          public void afterChunk() throws Exception

          {

            System.out.println("after chunk ....***************");


          }


          @Override

          public void beforeChunk() throws Exception

          {

            System.out.println("before chunk ....***************");


          }


          @Override

          public void onError(Exception arg0) throws Exception

          {

            // TODO Auto-generated method stub


          }


        }


this is the configuration xml file for spring batch context 

spring-batch-context.xml :






    <?xml version="1.0" encoding="UTF-8"?>

        <beans xmlns="http://www.springframework.org/schema/beans"

            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-3.2.xsd">


        <import resource="../jobs/jobPerson.xml" />

        <import resource="../config/spring-datasource.xml" />


        <!-- <context:annotation-config /> <tx:annotation-driven transaction-manager="transactionManager"/>a 

            PlatformTransactionManager is still required -->


        <!-- JobRepository and JobLauncher are configuration/setup classes -->

        <bean id="jobRepository"

            class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">

            <property name="dataSource" ref="dataSourceBatch" />

            <property name="transactionManager" ref="transactionManager" />

            <property name="databaseType" value="oracle" />

        </bean>



哈士奇WWW
浏览 469回答 1
1回答

BIG阳

该ChunkListener是有关chunk的配置,因此它需要内部被定义chunk这样的标签:<batch:job id="personJob">&nbsp; &nbsp; <batch:step id="step1bb1" >&nbsp; &nbsp; &nbsp; &nbsp; <batch:tasklet transaction-manager="transactionManager">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <batch:chunk reader="itemReader" writer="itemWriter" commit-interval="10" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<batch:listeners>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <batch:listener ref="chunkListener"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</batch:listeners>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </batch:chunk>&nbsp; &nbsp; &nbsp; &nbsp; </batch:tasklet>&nbsp; &nbsp; </batch:step>&nbsp; &nbsp; <batch:listeners>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<batch:listener ref="jobPersonListener" />&nbsp; &nbsp; </batch:listeners>&nbsp;</batch:job>此外,您PersonChunkListener实现了javax.batch.api.chunk.listener.ChunkListener接口,但它应该实现org.springframework.batch.core.ChunkListener。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java