Sei sulla pagina 1di 2


JobRepository is used for basic CRUD operations of the various persisted domain objects within Spring Batch, such as JobExecution and StepExecution. It is required by many of the major framework features, such as the JobLauncher, Job, and Step. <job-repository id="jobRepository" data-source="dataSourceRevamp" transaction-manager="transactionManager" isolation-level-for-create="READ_UNCOMMITTED" table-prefix="BATCH_"/>

When trying to launch from an HTTP request, a issues arises. In this scenario, the launching needs to be done asynchronously so that the SimpleJobLauncher returns immediately to its caller. This is because it is not good practice to keep an HTTP request open for the amount of time needed by long running processes such as batch. <beans:bean id="jobLauncher" class=""> <beans:property name="jobRepository" ref="jobRepository" /> <beans:property name="taskExecutor"> <beans:bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" /> </beans:property> </beans:bean>

A JobRegistry (and its parent interface JobLocator) is not mandatory, but it can be useful if you want to keep track of which jobs are available in the context. It is also useful for collecting jobs centrally in an application context when they have been created elsewhere (e.g. in child contexts). There is only one implementation provided by the framework <beans:bean id="jobRegistry" class="" />

JobOperator interface are most useful when used together(the JobRepository provides CRUD operations on the meta-data, and the JobExplorer provides read-only operations on the meta-data) to perform common monitoring tasks such as stopping, restarting, or summarizing a Job, as is commonly done by batch operators. <beans:bean id="jobOperator" class=""> <beans:property name="jobExplorer" ref="jobExplorer " /> <beans:property name="jobRepository" ref="jobRepository" /> <beans:property name="jobRegistry" ref="jobRegistry" /> <beans:property name="jobLauncher" ref="jobLauncher" /> </beans:bean>

The most basic need before any advanced features is the ability to query the repository for existing executions. This functionality is provided by the JobExplorer interface

<beans:bean id="jobExplorer" class=""> <beans:property name="dataSource" ref="dataSourceRevamp" /> </beans:bean>

This is a bean post-processor that can register all jobs as they are created: <beans:bean id="jobRegistryBeanPostProcessor" class=""> <beans:property name="jobRegistry" ref="jobRegistry" /> </beans:bean>

<beans:bean id="stepExecutionListener" class="com.springframework.batch.listener.StepExecutionListener"> <beans:property name="jobOperator" ref="jobOperator" /> </beans:bean>