From 6fa04a2ceef3964c0c3ed0c8c4d440b52a7c38e4 Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Wed, 26 Mar 2014 15:18:11 -0400 Subject: [PATCH] BATCH-2196: Document JobScope Updated documentation to reflect information gathered from Javadocs --- src/site/docbook/reference/step.xml | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/site/docbook/reference/step.xml b/src/site/docbook/reference/step.xml index 9630fc4b8..85258d0ab 100644 --- a/src/site/docbook/reference/step.xml +++ b/src/site/docbook/reference/step.xml @@ -1731,13 +1731,37 @@ itemWriter.write(items);
Job Scope - Job scope, introduced in Spring Batch 3.0 is similar to Step scope in configuration but is a scope for the job context and ensures there is only one instance of a particular bean for the entire Job. To Job scope your beans set the scope to "job": - - <bean id="jobScopedBean" scope="step" class="com.test.MyJobScopedBean"/> + Job scope, introduced in Spring Batch 3.0 is similar to Step scope + in configuration but is a Scope for the Job context so there is only one + instance of such a bean per executing job. Additionally, support is provided + for late binding of references accessible from the JobContext using + #{..} placeholders. Using this feature, bean properties can be pulled from + the job or job execution context and the job parameters. E.g. + + <bean id="..." class="..." scope="job"> + <property name="name" value="#{jobParameters[input]}" /> +</bean> - + <bean id="..." class="..." scope="job"> + <property name="name" value="#{jobExecutionContext['input.name']}.txt" /> +</bean> + + Because it is not part of the Spring container by default, the scope + must be added explicitly, either by using the batch namespace: + <beans xmlns="http://www.springframework.org/schema/beans" + xmlns:batch="http://www.springframework.org/schema/batch" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="..."> + + <batch:job .../> + ... + </beans> + + Or by including a bean definition explicitly for the JobScope (but not both): + + <bean class="org.springframework.batch.core.scope.JobScope" />