Skip to content

Commit 6fa04a2

Browse files
committed
BATCH-2196: Document JobScope
Updated documentation to reflect information gathered from Javadocs
1 parent db8b5d9 commit 6fa04a2

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/site/docbook/reference/step.xml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,13 +1731,37 @@ itemWriter.write(items);</programlisting>
17311731
<section id="job-scope">
17321732
<title>Job Scope</title>
17331733

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-
&lt;bean id=&quot;jobScopedBean&quot; scope=&quot;step&quot; class=&quot;com.test.MyJobScopedBean&quot;/&gt;
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>&lt;bean id=&quot;...&quot; class=&quot;...&quot; <emphasis role="bold">scope=&quot;job&quot;</emphasis>&gt;
1742+
&lt;property name=&quot;name&quot; value=&quot;#{jobParameters[input]}&quot; /&gt;
1743+
&lt;/bean&gt;
17371744
</programlisting>
1738-
</para>
1745+
<programlisting>&lt;bean id=&quot;...&quot; class=&quot;...&quot; <emphasis role="bold">scope=&quot;job&quot;</emphasis>&gt;
1746+
&lt;property name=&quot;name&quot; value=&quot;#{jobExecutionContext['input.name']}.txt&quot; /&gt;
1747+
&lt;/bean&gt;
1748+
</programlisting></para>
17391749

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>
17401752

1753+
<programlisting>&lt;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="..."&gt;
1757+
1758+
&lt;batch:job .../&gt;
1759+
...
1760+
&lt;/beans&gt;</programlisting>
1761+
1762+
<para>Or by including a bean definition explicitly for the <classname>JobScope</classname> (but not both):</para>
1763+
1764+
<programlisting>&lt;bean class="org.springframework.batch.core.scope.JobScope" /&gt;</programlisting>
17411765
</section>
17421766
</section>
17431767
</chapter>

0 commit comments

Comments
 (0)