Spring Batch规划好你的配置文件,用好Flow

随着项目规模扩大,Spring Batch配置管理成为挑战。推荐将基础配置置于applicationContext-batch.xml,Job配置置于applicationContext-batch-job.xml。利用Flow组织Steps集合,并通过parent属性实现属性继承,简化配置。
摘要由CSDN通过智能技术生成

随着项目的规模的不断扩大,Spring Batch的配置文件,也是一个头疼的问题,本人试了很多次,建议的配置方式如下:

基础配置放在一个文件中applicationContext-batch.xml:

<beans:beans xmlns="http://www.springframework.org/schema/batch"
	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:bean="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.xsd
	http://www.springframework.org/schema/batch
	http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
	
	<bean:bean id="jobRepository"
		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
		<bean:property name="transactionManager" ref="transactionManager" />
	</bean:bean>
	<bean:bean id="transactionManager"
		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager">
	</bean:bean>
	<bean:bean id="jobLauncher"
		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
		<bean:property name="jobRepository" ref="jobRepository" />
		<bean:property name="taskExecutor">
			<bean:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"></bean:bean>
		</bean:property>
	</bean:bean>
	
</beans:beans>

一个业务场景对应一个配置文件applicationContext-batch-mysteps.xml:

<beans:beans xmlns="http://www.springframework.org/schema/batch"
	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:bean="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.xsd
	http://www.springframework.org/schema/batch
	http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
	
	<flow id="mysteps_flow">
		<step id="mysteps_flow_first" parent="mysteps_first" next="mysteps_flow_second"></step>
		<step id="mysteps_flow_second" parent="mysteps_second" next="mysteps_flow_third"></step>
		<step id="mysteps_flow_third" parent="mysteps_third"></step>
	</flow>
	<step id="mysteps_first">
		<tasklet ref="first"></tasklet>
	</step>
	<step id="mysteps_second">
		<tasklet ref="second"></tasklet>
	</step>
	<step id="mysteps_third">
		<tasklet ref="third"></tasklet>
	</step>
	<bean:bean id="first" class="com.test.tasklet.MyFirstTasklet" scope="step">
	</bean:bean>
	<bean:bean id="second" class="com.test.tasklet.MySecondTasklet" scope="step">
	</bean:bean>
	<bean:bean id="third" class="com.test.tasklet.MyThirdTasklet" scope="step">
	</bean:bean>
</beans:beans>

业务场景的配置&#x
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值