如何找到使用spring批处理注释或xml文件的最佳方法?
首先,感谢大家的关注,在我的spring batch项目中定义了许多作业,例如:如何找到使用spring批处理注释或xml文件的最佳方法?,spring,spring-batch,Spring,Spring Batch,首先,感谢大家的关注,在我的spring batch项目中定义了许多作业,例如: <batch:job id="helloWorldJob1" job-repository="jobRepository"> <batch:step id="step1" > <batch:tasklet> <batch:chunk reader="itemReader1
<batch:job id="helloWorldJob1" job-repository="jobRepository">
<batch:step id="step1" >
<batch:tasklet>
<batch:chunk reader="itemReader1" writer="itemWriter1"
processor="itemProcessor1">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<batch:job id="helloWorldJob2" job-repository="jobRepository">
<batch:step id="step1" >
<batch:tasklet>
<batch:chunk reader="itemReader2" writer="itemWriter2"
processor="itemProcessor2">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<batch:job id="helloWorldJob3" job-repository="jobRepository">
<batch:step id="step1" >
<batch:tasklet>
<batch:chunk reader="itemReader3" writer="itemWriter3"
processor="itemProcessor3">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
.
.
.
.
.
.
.
.
如何使用纯注释?这是正确的方法吗?基本上是一个良好的开端。这里唯一需要注意的是,这个示例有一个作业,当您执行
mvn spring引导:运行
<代码>批配置是纯java配置的示例
在我们的项目中,我们创建了如下主配置:
@Configuration
@EnableBatchProcessing(modular = true)
public class JobContextConfig {
@Autowired
private JobRepository jobRepository;
@Bean
public ApplicationContextFactory helloWorldJob1Job() {
return new GenericApplicationContextFactory(HelloWorldJob1JobConfig.class);
}
@Bean
public ApplicationContextFactory helloWorldJob2Job() {
return new GenericApplicationContextFactory(HelloWorldJob2JobConfig.class);
}
@Bean
public ApplicationContextFactory helloWorldJob3Job() {
return new GenericApplicationContextFactory(HelloWorldJob3JobConfig.class);
}
}
对于每个作业,我们在不同的上下文中有单独的配置HelloWorldJob1JobConfig
将保存该作业所需的所有内容,并且该类看起来像spring示例中的BatchConfiguration
。这将创建除触发之外所需的所有内容,因此我们为每个作业创建了启动器(我们正在通过http启动一些作业,有些是通过消息传递启动的,有些是手动启动的,因此我们需要实际启动通过JobLauncher
以这种方式定义的作业)
将springbatch
与springboot
与纯java配置集成的另一个好资源是