13 lines
2.7 KiB
HTML
13 lines
2.7 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Contexts</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch12s06.xhtml" title="Running a job"/><link rel="next" href="ch12s08.xhtml" title="Step Flow"/></head><body><header/><section class="section" title="Contexts" epub:type="subchapter" id="jsrContexts"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Contexts</h2></div></div></div><p>JSR-352 defines two context objects that are used to interact with the meta-data of a job or step from
|
|
within a batch artifact: <code class="classname">javax.batch.runtime.context.JobContext</code> and
|
|
<code class="classname">javax.batch.runtime.context.StepContext</code>. Both of these are available in any step
|
|
level artifact (<code class="classname">Batchlet</code>, <code class="classname">ItemReader</code>, etc) with the
|
|
<code class="classname">JobContext</code> being available to job level artifacts as well
|
|
(<code class="classname">JobListener</code> for example).</p><p>To obtain a reference to the <code class="classname">JobContext</code> or <code class="classname">StepContext</code>
|
|
within the current scope, simply use the <code class="classname">@Inject</code> annotation:</p><pre class="programlisting">@Inject
|
|
JobContext jobContext;
|
|
</pre><div class="note" title="@Autowire for JSR-352 contexts" epub:type="notice"><table style="border: 0; "><tr><td style="text-align: center; vertical-align: top; width: 25; " rowspan="2"><img alt="[Note]" src="images/note.png"/></td><th style="text-align: left; ">@Autowire for JSR-352 contexts</th></tr><tr><td style="text-align: left; vertical-align: top; "><p>Using Spring's @Autowire is not supported for the injection of these contexts.</p></td></tr></table></div><p>In Spring Batch, the <code class="classname">JobContext</code> and <code class="classname">StepContext</code> wrap their
|
|
corresponding execution objects (<code class="classname">JobExecution</code> and
|
|
<code class="classname">StepExecution</code> respectively). Data stored via
|
|
<code class="classname">StepContext#persistent#setPersistentUserData(Serializable data)</code> is stored in the
|
|
Spring Batch <code class="classname">StepExecution#executionContext</code>.</p></section><footer/></body></html> |