Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring batch Spring批处理:无法记录跳过的项目,未调用skiplistener,提交期间发生异常_Spring Batch - Fatal编程技术网

Spring batch Spring批处理:无法记录跳过的项目,未调用skiplistener,提交期间发生异常

Spring batch Spring批处理:无法记录跳过的项目,未调用skiplistener,提交期间发生异常,spring-batch,Spring Batch,batch-job.xml <bean id="multiResourceReader" class=" org.springframework.batch.item.file.MultiResourceItemReader"> <property name="resources" value="file:${daper.batch.file.inbound.directory.file}" /> <property name="delega

batch-job.xml

<bean id="multiResourceReader"
    class=" org.springframework.batch.item.file.MultiResourceItemReader">
    <property name="resources" value="file:${daper.batch.file.inbound.directory.file}" />
    <property name="delegate" ref="cvsFileItemReader" />
</bean>

<bean id="Listener" class="com.batch.RecordListener" scope="step"></bean>

<bean id="oracleDBWriter" class="com.batch.OracleDBItemWriter"/>

<batch:step id="readAndSaveData" >
    <batch:tasklet transaction-manager="transactionManager">
        <batch:transaction-attributes isolation="READ_COMMITTED" 
                                      propagation="REQUIRES_NEW" timeout="200"/>
        <batch:chunk reader="multiResourceReader" writer="oracleDBWriter" 
                     commit-interval="1"  skip-limit="10">
            <batch:skippable-exception-classes>
                <batch:include class="org.springframework.batch.item.file.FlatFileParseException" />
                <batch:include class="org.springframework.batch.item.WriteFailedException" />
                <batch:include class="org.springframework.batch.item.WriteFailedException" />
                <batch:include class="org.hibernate.exception.ConstraintViolationException" />
                <batch:include class="org.springframework.dao.DataIntegrityViolationException" />
            </batch:skippable-exception-classes>
        </batch:chunk>


        <batch:no-rollback-exception-classes>
            <batch:include class="org.springframework.batch.item.file.FlatFileParseException" />
            <batch:include class="org.springframework.batch.item.WriteFailedException" />
            <batch:include class="org.springframework.batch.item.WriteFailedException" />
            <batch:include class="org.hibernate.exception.ConstraintViolationException" />
            <batch:include class="org.springframework.dao.DataIntegrityViolationException" />
        </batch:no-rollback-exception-classes>
    </batch:tasklet>
    <batch:listeners>
        <batch:listener ref="Listener"/>
    </batch:listeners>
这里---当异常发生时,不调用skiplistener,也不调用afterchunk。搜索了许多论坛并跟踪了代码示例..不起作用
请帮助

为什么将相同的异常配置为跳过和不回滚?我只是在尝试。即使未删除任何回滚异常,也不会调用skiplistener。如果在提交期间发生异常,则跳过该项,作业成功。但是,在使用multiresourceitemreader时,chunklistener的afterchunk没有被调用,skiplistener也没有被调用。这就是问题所在吗?
    public class RecordListener extends SkipListenerSupport implements ChunkListener,StepExecutionListener,ItemWriteListener {



        @Override
        public void onSkipInRead(Throwable t) {
            System.out.println("skipped item: {} "+t.toString());
        }


        @Override
        public void onSkipInWrite(Object item, Throwable t) {
            // TODO Auto-generated method stub
            System.out.println("inside skip write item "+item.toString());
            System.out.println("error is "+t.getMessage());

        }

        @Override
        public void onSkipInProcess(Object item, Throwable t) {
            // TODO Auto-generated method stub
            System.out.println("inside skip process item "+item.toString());
            System.out.println("error is "+t.getMessage());
        }


        @Override
        public void beforeChunk() {
            // TODO Auto-generated method stub
            System.out.println("inside befre chunk");
        }


        @Override
        public void afterChunk() {
            // TODO Auto-generated method stub
            System.out.println("inside after chunk");

        }


        @Override
        public void beforeStep(StepExecution stepExecution) {
            // TODO Auto-generated method stub
            System.out.println("before step");
        }


        @Override
        public ExitStatus afterStep(StepExecution stepExecution) {
            // TODO Auto-generated method stub
            System.out.println("aftr step");
            return null;
        }


        @Override
        public void beforeWrite(List items) {
            // TODO Auto-generated method stub
        System.out.println("inside beforewrite");

        }


        @Override
        public void afterWrite(List items) {
            // TODO Auto-generated method stub
            System.out.println("afterWrite");

        }


        @Override
        public void onWriteError(Exception exception, List items) {
            // TODO Auto-generated method stub
            System.out.println("onWriteError");

        }

        /*@Override
        public void onSkipInRead(Throwable t) {
            System.out.println("insid skipread");

        }

        @Override
        public void onSkipInWrite(Object item, Throwable t) {
            // TODO Auto-generated method stub
            System.out.println("inside skip write item "+item.toString());
            System.out.println("error is "+t.getMessage());

        }

        @Override
        public void onSkipInProcess(Object item, Throwable t) {
            // TODO Auto-generated method stub
            System.out.println("inside skip process item "+item.toString());
            System.out.println("error is "+t.getMessage());
        }

        @Override
        public void beforeWrite(List<? extends StudentAthlete> items) {
            // TODO Auto-generated method stub
            System.out.println("inside beforewrite");
        }

        @Override
        public void afterWrite(List<? extends StudentAthlete> items) {
            // TODO Auto-generated method stub
            System.out.println("inside afterwrite");
        }

        @Override
        public void onWriteError(Exception exception,
                List<? extends StudentAthlete> items) {
            // TODO Auto-generated method stub
            System.out.println("inside onwriteerror itemssize "+items.size());

            for(StudentAthlete studentAthlete:items){
                System.out.println("studentathlete :" +studentAthlete.getMitId()+" "+studentAthlete.getAssignedSport());
            }

        }

        @Override
        public void beforeStep(StepExecution stepExecution) {
            // TODO Auto-generated method stub
            System.out.println("inside stepexecution");
            JobExecution jobExecution = stepExecution.getJobExecution();
            ExecutionContext jobContext = jobExecution.getExecutionContext();


        }

        @Override
        public ExitStatus afterStep(StepExecution stepExecution) {
            // TODO Auto-generated method stub
            System.out.println("inside afterstep");
            return null;
        }
}
[] [INFO ] [2014-11-25 08:59:11,298] [org.springframework.batch.core.job.SimpleStepHandler] - Executing step: [readAndSaveData]
before step
inside befre chunk
inside beforewrite
[] [DEBUG] [2014-11-25 08:59:11,470] [edu.mit.daper.ftstatus.batch.OracleDBItemWriter] - step: readAndSaveData :OracleDBWriter :Write
[] [DEBUG] [2014-11-25 08:59:11,517] [edu.mit.daper.ftstatus.batch.OracleDBItemWriter] - student size 1  [Student{ id : 7E112B130A0937D200000149E73FB16E ; version : null ;  } ]

[] [DEBUG] [2014-11-25 08:59:11,517] [edu.mit.csf.daper.ftstatus.dao.hibernate.HibernateStudentDao] - HibernateStudentDao : SAVE 
[] [DEBUG] [2014-11-25 08:59:11,517] [edu.mit.daper.ftstatus.batch.OracleDBItemWriter] - step: readAndSaveDAta completed
afterWrite
[] [DEBUG] [2014-11-25 08:59:11,517] [org.hibernate.SQL] - insert into student (VERSION, ID, SPORT, CREATE_DATE, CREATE_BY, MODIFY_DATE, MODIFY_BY, STUDENT_KEY) values (?, ?, ?, ?, ?, ?, ?, ?)
[] [WARN ] [2014-11-25 08:59:11,532] [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 2291, SQLState: 23000
[] [ERROR] [2014-11-25 08:59:11,532] [org.hibernate.util.JDBCExceptionReporter] - ORA-02291: integrity constraint (testschema.SA_ASSIGNED_SPORT_FK) violated - parent key not found

[] [WARN ] [2014-11-25 08:59:11,532] [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 2291, SQLState: 23000
[] [ERROR] [2014-11-25 08:59:11,532] [org.hibernate.util.JDBCExceptionReporter] - ORA-02291: integrity constraint (testschema.SA_ASSIGNED_SPORT_FK) violated - parent key not found

[] [INFO ] [2014-11-25 08:59:11,532] [org.springframework.batch.core.step.tasklet.TaskletStep] - Commit failed while step execution data was already updated. Reverting to old version.
inside befre chunk
inside beforewrite
[] [DEBUG] [2014-11-25 08:59:11,580] [edu.mit.daper.ftstatus.batch.OracleDBItemWriter] - step: readAndSaveData :OracleDBWriter :Write
[] [DEBUG] [2014-11-25 08:59:11,580] [edu.mit.daper.ftstatus.batch.OracleDBItemWriter] - studentList size 1  [Student { id : 7CF682410A0937D200000149E73FB1DC ; version : null ;  } ]

[] [DEBUG] [2014-11-25 08:59:11,580] [edu.mit.csf.daper.ftstatus.dao.hibernate.HibernateStudentAthleteDao] - HibernateStudentAthleteDao : SAVE :about to save 900003588
[] [DEBUG] [2014-11-25 08:59:11,580] [edu.mit.daper.ftstatus.batch.OracleDBItemWriter] - step: readAndSaveDAta completed
afterWrite
[] [DEBUG] [2014-11-25 08:59:11,596] [org.hibernate.SQL] - insert into student (VERSION, ID, SPORT, CREATE_DATE, CREATE_BY, MODIFY_DATE, MODIFY_BY, STUDENT_KEY) values (?, ?, ?, ?, ?, ?, ?, ?)
inside after chunk
inside befre chunk
inside beforewrite