@@ -50,8 +50,10 @@ public class ItemFailureLoggerListener extends ItemListenerSupport {
50
50
}
51
51
----
52
52
53
- Having implemented this listener, it must be registered with a step, as shown in the
54
- following example:
53
+ Having implemented this listener, it must be registered with a step.
54
+
55
+ [role="xmlContent"]
56
+ The following example shows how to register a listener with a step in XML:
55
57
56
58
.XML Configuration
57
59
[source, xml, role="xmlContent"]
@@ -66,6 +68,9 @@ following example:
66
68
</step>
67
69
----
68
70
71
+ [role="javaContent"]
72
+ The following example shows how to register a listener with a step Java:
73
+
69
74
.Java Configuration
70
75
[source, java, role="javaContent"]
71
76
----
@@ -134,8 +139,10 @@ public class EarlyCompletionItemReader implements ItemReader<T> {
134
139
The previous example actually relies on the fact that there is a default implementation
135
140
of the `CompletionPolicy` strategy that signals a complete batch when the item to be
136
141
processed is `null`. A more sophisticated completion policy could be implemented and
137
- injected into the `Step` through the `SimpleStepFactoryBean`, as shown in the following
138
- example:
142
+ injected into the `Step` through the `SimpleStepFactoryBean`.
143
+
144
+ [role="xmlContent"]
145
+ The following example shows how to inject a completion policy into a step in XML:
139
146
140
147
.XML Configuration
141
148
[source, xml, role="xmlContent"]
@@ -150,6 +157,9 @@ example:
150
157
<bean id="completionPolicy" class="org.example...SpecialCompletionPolicy"/>
151
158
----
152
159
160
+ [role="javaContent"]
161
+ The following example shows how to inject a completion policy into a step in Java:
162
+
153
163
.Java Configuration
154
164
[source, java, role="javaContent"]
155
165
----
@@ -196,12 +206,15 @@ so this is always an abnormal ending to a job.
196
206
[[addingAFooterRecord]]
197
207
=== Adding a Footer Record
198
208
199
- Often, when writing to flat files, a "footer" record must be appended to the end of the
209
+ Often, when writing to flat files, a "` footer` " record must be appended to the end of the
200
210
file, after all processing has be completed. This can be achieved using the
201
211
`FlatFileFooterCallback` interface provided by Spring Batch. The `FlatFileFooterCallback`
202
212
(and its counterpart, the `FlatFileHeaderCallback`) are optional properties of the
203
- `FlatFileItemWriter` and can be added to an item writer as shown in the following
204
- example:
213
+ `FlatFileItemWriter` and can be added to an item writer.
214
+
215
+ [role="xmlContent"]
216
+ The following example shows how to use the `FlatFileHeaderCallback` and the
217
+ `FlatFileFooterCallback` in XML:
205
218
206
219
.XML Configuration
207
220
[source, xml, role="xmlContent"]
@@ -214,6 +227,10 @@ example:
214
227
</bean>
215
228
----
216
229
230
+ [role="javaContent"]
231
+ The following example shows how to use the `FlatFileHeaderCallback` and the
232
+ `FlatFileFooterCallback` in Java:
233
+
217
234
.Java Configuration
218
235
[source, java, role="javaContent"]
219
236
----
@@ -292,7 +309,10 @@ method, once we are guaranteed that no exceptions are thrown, that we update the
292
309
293
310
In order for the `writeFooter` method to be called, the `TradeItemWriter` (which
294
311
implements `FlatFileFooterCallback`) must be wired into the `FlatFileItemWriter` as the
295
- `footerCallback`. The following example shows how to do so:
312
+ `footerCallback`.
313
+
314
+ [role="xmlContent"]
315
+ The following example shows how to wire the `TradeItemWriter` in XML:
296
316
297
317
.XML Configuration
298
318
[source, xml, role="xmlContent"]
@@ -308,6 +328,9 @@ implements `FlatFileFooterCallback`) must be wired into the `FlatFileItemWriter`
308
328
</bean>
309
329
----
310
330
331
+ [role="javaContent"]
332
+ The following example shows how to wire the `TradeItemWriter` in Java:
333
+
311
334
.Java Configuration
312
335
[source, java, role="javaContent"]
313
336
----
@@ -409,7 +432,10 @@ multi-line record as a group, so that it can be passed to the `ItemWriter` intac
409
432
Because a single record spans multiple lines and because we may not know how many lines
410
433
there are, the `ItemReader` must be careful to always read an entire record. In order to
411
434
do this, a custom `ItemReader` should be implemented as a wrapper for the
412
- `FlatFileItemReader`, as shown in the following example:
435
+ `FlatFileItemReader`.
436
+
437
+ [role="xmlContent"]
438
+ The following example shows how to implement a custom `ItemReader` in XML:
413
439
414
440
.XML Configuration
415
441
[source, xml, role="xmlContent"]
@@ -429,6 +455,9 @@ do this, a custom `ItemReader` should be implemented as a wrapper for the
429
455
</bean>
430
456
----
431
457
458
+ [role="javaContent"]
459
+ The following example shows how to implement a custom `ItemReader` in Java:
460
+
432
461
.Java Configuration
433
462
[source, java, role="javaContent"]
434
463
----
@@ -459,7 +488,10 @@ delegate `FlatFileItemReader`. See
459
488
link:readersAndWriters.html#flatFileItemReader[`FlatFileItemReader` in the Readers and
460
489
Writers chapter] for more details. The delegate reader then uses a
461
490
`PassThroughFieldSetMapper` to deliver a `FieldSet` for each line back to the wrapping
462
- `ItemReader`, as shown in the following example:
491
+ `ItemReader`.
492
+
493
+ [role="xmlContent"]
494
+ The following example shows how to ensure that each line is properly tokenized in XML:
463
495
464
496
.XML Content
465
497
[source, xml, role="xmlContent"]
@@ -476,6 +508,9 @@ Writers chapter] for more details. The delegate reader then uses a
476
508
</bean>
477
509
----
478
510
511
+ [role="javaContent"]
512
+ The following example shows how to ensure that each line is properly tokenized in Java:
513
+
479
514
.Java Content
480
515
[source, java, role="javaContent"]
481
516
----
@@ -545,7 +580,10 @@ common metadata about the run would be lost. Furthermore, a multi-step job would
545
580
need to be split up into multiple jobs as well.
546
581
547
582
Because the need is so common, Spring Batch provides a `Tasklet` implementation for
548
- calling system commands, as shown in the following example:
583
+ calling system commands.
584
+
585
+ [role="xmlContent"]
586
+ The following example shows how to call an external command in XML:
549
587
550
588
.XML Configuration
551
589
[source, xml, role="xmlContent"]
@@ -557,6 +595,9 @@ calling system commands, as shown in the following example:
557
595
</bean>
558
596
----
559
597
598
+ [role="javaContent"]
599
+ The following example shows how to call an external command in Java:
600
+
560
601
.Java Configuration
561
602
[source, java, role="javaContent"]
562
603
----
@@ -639,13 +680,16 @@ public class SavingItemWriter implements ItemWriter<Object> {
639
680
}
640
681
----
641
682
642
- To make the data available to future `Steps`, it must be "promoted" to the `Job`
683
+ To make the data available to future `Steps`, it must be "` promoted` " to the `Job`
643
684
`ExecutionContext` after the step has finished. Spring Batch provides the
644
685
`ExecutionContextPromotionListener` for this purpose. The listener must be configured
645
686
with the keys related to the data in the `ExecutionContext` that must be promoted. It can
646
687
also, optionally, be configured with a list of exit code patterns for which the promotion
647
688
should occur (`COMPLETED` is the default). As with all listeners, it must be registered
648
- on the `Step` as shown in the following example:
689
+ on the `Step`.
690
+
691
+ [role="xmlContent"]
692
+ The following example shows how to promote a step to the `Job` `ExecutionContext` in XML:
649
693
650
694
.XML Configuration
651
695
[source, xml, role="xmlContent"]
@@ -674,6 +718,9 @@ on the `Step` as shown in the following example:
674
718
</beans:bean>
675
719
----
676
720
721
+ [role="xmlContent"]
722
+ The following example shows how to promote a step to the `Job` `ExecutionContext` in Java:
723
+
677
724
.Java Configuration
678
725
[source, java, role="javaContent"]
679
726
----
0 commit comments