Spring 批处理 -运行 JobLauncher
Spring batch -Run JobLauncher
我在我的项目中集成了 Spring 批处理,但我在 运行 JobLauncher 中遇到了问题。
在我的 class JobLauncher 中我有这个 :
public class XXXJobLauncher {
@Autowired
@Qualifier("testJob")
Job testJob;
@Autowired
JobLauncher jobLauncher;
@ServiceActivator
public void run(FileMetaData fileMetaData) {
///
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("uuiid", fileMetaData.getUuid());
jobParametersBuilder.addLong("id", dataImport.getId());
try {
jobLauncher.run(testJob, jobParametersBuilder.toJobParameters());
} catch (JobExecutionAlreadyRunningException | JobRestartException | JobParametersInvalidException | JobInstanceAlreadyCompleteException e) {
e.printStackTrace();
}
}
对于我使用的配置 XML 配置:
ConfigBatch.xml:
<import resource="classpath:job-config.xml"/>
<bean id="jobRepositoryFactory" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="tablePrefix" value="BATCH_"/>
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository"
factory-bean="jobRepositoryFactory"/>
<bean id="batchTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
destroy-method="shutdown">
<property name="corePoolSize" value="6"/>
<property name="allowCoreThreadTimeOut" value="true"/>
<property name="waitForTasksToCompleteOnShutdown" value="true"/>
</bean>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
<property name="taskExecutor" ref="batchTaskExecutor"/>
</bean>
在工作-Config.xml我有:
<batch:job id="testJob"
incrementer="incrementer"
job-repository="jobRepository">
<batch:step id="Step1">
<batch:tasklet throttle-limit="4"
transaction-manager="transactionManager"
task-executor="batchTaskExecutor">
<batch:chunk reader="XXXReader"
processor="passThroughItemProcessor"
writer="XXXWriter"
skip-limit="100"
commit-interval="10">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.batch.item.file.FlatFileParseException"/>
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="XXXListener"/>
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="XXXReader"
class="com.reader.XXXReader"
scope="step">
<constructor-arg value="#{jobParameters[uuiid]}" name="uuiid"/>
</bean>
<bean id="XXXWriter"
class="com.writer.XXXWriter"
scope="step">
<constructor-arg value="#{jobParameters[ id]}" name="id"/>
</bean>
<bean id="XXXListener"
class="com.listener.XXXListener">
</bean>
<bean id="passThroughItemProcessor" class="org.springframework.batch.item.support.PassThroughItemProcessor"/>
<bean id="incrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
当我在 class JobLauncher 中调试时,它在 jobLuancher.run 中停止,我也不例外,似乎 spring 批处理无法识别 reader 和 whriter! !有什么建议吗?
我解决了 batchConfig.xml 中的问题:
<batch:job-repository id="jobRepository"
data-source="dataSource"
transaction-manager="batchTransactionManager"/>
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="batchTransactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
<bean id="batchTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
destroy-method="shutdown">
<property name="corePoolSize" value="4"/>
<property name="allowCoreThreadTimeOut" value="true"/>
<property name="waitForTasksToCompleteOnShutdown" value="true"/>
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
</bean>
我在我的项目中集成了 Spring 批处理,但我在 运行 JobLauncher 中遇到了问题。
在我的 class JobLauncher 中我有这个 :
public class XXXJobLauncher {
@Autowired
@Qualifier("testJob")
Job testJob;
@Autowired
JobLauncher jobLauncher;
@ServiceActivator
public void run(FileMetaData fileMetaData) {
///
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("uuiid", fileMetaData.getUuid());
jobParametersBuilder.addLong("id", dataImport.getId());
try {
jobLauncher.run(testJob, jobParametersBuilder.toJobParameters());
} catch (JobExecutionAlreadyRunningException | JobRestartException | JobParametersInvalidException | JobInstanceAlreadyCompleteException e) {
e.printStackTrace();
}
}
对于我使用的配置 XML 配置:
ConfigBatch.xml:
<import resource="classpath:job-config.xml"/>
<bean id="jobRepositoryFactory" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="tablePrefix" value="BATCH_"/>
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository"
factory-bean="jobRepositoryFactory"/>
<bean id="batchTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
destroy-method="shutdown">
<property name="corePoolSize" value="6"/>
<property name="allowCoreThreadTimeOut" value="true"/>
<property name="waitForTasksToCompleteOnShutdown" value="true"/>
</bean>
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
<property name="taskExecutor" ref="batchTaskExecutor"/>
</bean>
在工作-Config.xml我有:
<batch:job id="testJob"
incrementer="incrementer"
job-repository="jobRepository">
<batch:step id="Step1">
<batch:tasklet throttle-limit="4"
transaction-manager="transactionManager"
task-executor="batchTaskExecutor">
<batch:chunk reader="XXXReader"
processor="passThroughItemProcessor"
writer="XXXWriter"
skip-limit="100"
commit-interval="10">
<batch:skippable-exception-classes>
<batch:include class="org.springframework.batch.item.file.FlatFileParseException"/>
</batch:skippable-exception-classes>
<batch:listeners>
<batch:listener ref="XXXListener"/>
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="XXXReader"
class="com.reader.XXXReader"
scope="step">
<constructor-arg value="#{jobParameters[uuiid]}" name="uuiid"/>
</bean>
<bean id="XXXWriter"
class="com.writer.XXXWriter"
scope="step">
<constructor-arg value="#{jobParameters[ id]}" name="id"/>
</bean>
<bean id="XXXListener"
class="com.listener.XXXListener">
</bean>
<bean id="passThroughItemProcessor" class="org.springframework.batch.item.support.PassThroughItemProcessor"/>
<bean id="incrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
当我在 class JobLauncher 中调试时,它在 jobLuancher.run 中停止,我也不例外,似乎 spring 批处理无法识别 reader 和 whriter! !有什么建议吗?
我解决了 batchConfig.xml 中的问题:
<batch:job-repository id="jobRepository"
data-source="dataSource"
transaction-manager="batchTransactionManager"/>
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="batchTransactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
<bean id="batchTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
destroy-method="shutdown">
<property name="corePoolSize" value="4"/>
<property name="allowCoreThreadTimeOut" value="true"/>
<property name="waitForTasksToCompleteOnShutdown" value="true"/>
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
</bean>