@@ -1731,13 +1731,37 @@ itemWriter.write(items);</programlisting>
1731
1731
<section id =" job-scope" >
1732
1732
<title >Job Scope</title >
1733
1733
1734
- <para >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":
1735
- <programlisting >
1736
- < bean id=" jobScopedBean" scope=" step" class=" com.test.MyJobScopedBean" />
1734
+ <para >Job scope, introduced in Spring Batch 3.0 is similar to Step scope
1735
+ in configuration but is a Scope for the Job context so there is only one
1736
+ instance of such a bean per executing job. Additionally, support is provided
1737
+ for late binding of references accessible from the JobContext using
1738
+ #{..} placeholders. Using this feature, bean properties can be pulled from
1739
+ the job or job execution context and the job parameters. E.g.
1740
+
1741
+ <programlisting >< bean id=" ..." class=" ..." <emphasis role =" bold" >scope=" job" </emphasis >>
1742
+ < property name=" name" value=" #{jobParameters[input]}" />
1743
+ < /bean>
1737
1744
</programlisting >
1738
- </para >
1745
+ <programlisting >< bean id=" ..." class=" ..." <emphasis role =" bold" >scope=" job" </emphasis >>
1746
+ < property name=" name" value=" #{jobExecutionContext['input.name']}.txt" />
1747
+ < /bean>
1748
+ </programlisting ></para >
1739
1749
1750
+ <para >Because it is not part of the Spring container by default, the scope
1751
+ must be added explicitly, either by using the <literal >batch</literal > namespace:</para >
1740
1752
1753
+ <programlisting >< beans xmlns="http://www.springframework.org/schema/beans"
1754
+ xmlns:batch="http://www.springframework.org/schema/batch"
1755
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1756
+ xsi:schemaLocation="...">
1757
+
1758
+ < batch:job .../>
1759
+ ...
1760
+ < /beans> </programlisting >
1761
+
1762
+ <para >Or by including a bean definition explicitly for the <classname >JobScope</classname > (but not both):</para >
1763
+
1764
+ <programlisting >< bean class="org.springframework.batch.core.scope.JobScope" /> </programlisting >
1741
1765
</section >
1742
1766
</section >
1743
1767
</chapter >
0 commit comments