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.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
这个文件放在src/main/resources文件夹下。
[html]
com.test.tasklet.MyFirstTasklet
com.test.tasklet.MyFirstTasklet的代码如下:
[java]
/**
*
*/
package com.test.tasklet;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
/**
* @author hadoop
*
*/
public class MyFirstTasklet implements Tasklet {
/* (non-Javadoc)
* @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext)
*/
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
throws Exception {
for(int i = 0; i < 10; i++)
{
System.out.println(i);
}
return RepeatStatus.FINISHED;
}
}
/**
*
*/
package com.test.tasklet;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
/**
* @author hadoop
*
*/
public class MyFirstTasklet implements Tasklet {
/* (non-Javadoc)
* @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext)
*/
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
throws Exception {
for(int i = 0; i < 10; i++)
{
System.out.println(i);
}
return RepeatStatus.FINISHED;
}
}
main函数:
[java]
/**
*
*/
package com.test.springbatch;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompl