@@ -60,15 +60,14 @@ global to all steps, such as restartability. The job configuration contains:
60
60
* Definition and ordering of `Step` instances.
61
61
* Whether or not the job is restartable.
62
62
63
- ifdef::backend-html5 []
63
+ ifdef::backend-spring-html []
64
64
[role="javaContent"]
65
65
For those who use Java configuration, Spring Batch provides a default implementation of
66
66
the `Job` interface in the form of the `SimpleJob` class, which creates some standard
67
67
functionality on top of `Job`. When using Java-based configuration, a collection of
68
68
builders is made available for the instantiation of a `Job`, as the following
69
69
example shows:
70
70
71
- ====
72
71
[source, java, role="javaContent"]
73
72
----
74
73
@Bean
@@ -80,7 +79,6 @@ public Job footballJob(JobRepository jobRepository) {
80
79
.build();
81
80
}
82
81
----
83
- ====
84
82
85
83
[role="xmlContent"]
86
84
For those who use XML configuration, Spring Batch provides a default implementation of the
@@ -89,7 +87,6 @@ functionality on top of `Job`. However, the batch namespace abstracts away the n
89
87
instantiate it directly. Instead, you can use the `<job>` element, as the
90
88
following example shows:
91
89
92
- ====
93
90
[source, xml, role="xmlContent"]
94
91
----
95
92
<job id="footballJob">
@@ -98,16 +95,14 @@ following example shows:
98
95
<step id="playerSummarization"/>
99
96
</job>
100
97
----
101
- ====
102
- endif::backend-html5[]
98
+ endif::backend-spring-html[]
103
99
104
100
ifdef::backend-pdf[]
105
101
Spring Batch provides a default implementation of the `Job` interface in the form of the
106
102
`SimpleJob` class, which creates some standard functionality on top of `Job`. When using
107
103
Java-based configuration, a collection of builders are made available for the
108
104
instantiation of a `Job`, as the following example shows:
109
105
110
- ====
111
106
[source, java]
112
107
----
113
108
@Bean
@@ -119,13 +114,11 @@ public Job footballJob(JobRepository jobRepository) {
119
114
.build();
120
115
}
121
116
----
122
- ====
123
117
124
118
However, when using XML configuration, the batch namespace abstracts away the need to
125
119
instantiate it directly. Instead, you can use the `<job>` element, as the following
126
120
example shows:
127
121
128
- ====
129
122
[source, xml]
130
123
----
131
124
<job id="footballJob">
@@ -134,7 +127,6 @@ example shows:
134
127
<step id="playerSummarization"/>
135
128
</job>
136
129
----
137
- ====
138
130
endif::backend-pdf[]
139
131
140
132
==== JobInstance
@@ -163,6 +155,7 @@ from previous executions is used. Using a new `JobInstance` means "`start from t
163
155
beginning,`" and using an existing instance generally means "`start from where you left
164
156
off`".
165
157
158
+ [[jobParameters]]
166
159
==== JobParameters
167
160
168
161
Having discussed `JobInstance` and how it differs from `Job`, the natural question to ask
@@ -447,12 +440,10 @@ or even if the power goes out. All that is needed is to put the current number o
447
440
read into the context, as the following example shows, and the framework does the
448
441
rest:
449
442
450
- ====
451
443
[source, java]
452
444
----
453
445
executionContext.putLong(getKey(LINES_READ_COUNT), reader.getPosition());
454
446
----
455
- ====
456
447
457
448
Using the `EndOfDay` example from the `Job` stereotypes section as an example, assume there
458
449
is one step, `loadData`, that loads a file into the database. After the first failed run,
@@ -513,7 +504,6 @@ the last run are reconstituted from the database. When the `ItemReader` is opene
513
504
check to see if it has any stored state in the context and initialize itself from there,
514
505
as the following example shows:
515
506
516
- ====
517
507
[source, java]
518
508
----
519
509
if (executionContext.containsKey(getKey(LINES_READ_COUNT))) {
@@ -529,7 +519,6 @@ if (executionContext.containsKey(getKey(LINES_READ_COUNT))) {
529
519
}
530
520
}
531
521
----
532
- ====
533
522
534
523
In this case, after the preceding code runs, the current line is 40,322, letting the `Step`
535
524
start again from where it left off. You can also use the `ExecutionContext` for
@@ -557,14 +546,12 @@ Note that there is at least one `ExecutionContext` per
557
546
`JobExecution` and one for every `StepExecution`. For example, consider the following
558
547
code snippet:
559
548
560
- ====
561
549
[source, java]
562
550
----
563
551
ExecutionContext ecStep = stepExecution.getExecutionContext();
564
552
ExecutionContext ecJob = jobExecution.getExecutionContext();
565
553
//ecStep does not equal ecJob
566
554
----
567
- ====
568
555
569
556
As noted in the comment, `ecStep` does not equal `ecJob`. They are two different
570
557
`ExecutionContexts`. The one scoped to the `Step` is saved at every commit point in the
@@ -582,12 +569,10 @@ by passing them to the repository.
582
569
The Spring Batch XML namespace provides support for configuring a `JobRepository` instance
583
570
with the `<job-repository>` tag, as the following example shows:
584
571
585
- ====
586
572
[source, xml, role="xmlContent"]
587
573
----
588
574
<job-repository id="jobRepository"/>
589
575
----
590
- ====
591
576
592
577
[role="javaContent"]
593
578
When using Java configuration, the `@EnableBatchProcessing` annotation provides a
@@ -598,7 +583,6 @@ When using Java configuration, the `@EnableBatchProcessing` annotation provides
598
583
`JobLauncher` represents a simple interface for launching a `Job` with a given set of
599
584
`JobParameters`, as the following example shows:
600
585
601
- ====
602
586
[source, java]
603
587
----
604
588
public interface JobLauncher {
@@ -608,7 +592,6 @@ public JobExecution run(Job job, JobParameters jobParameters)
608
592
JobInstanceAlreadyCompleteException, JobParametersInvalidException;
609
593
}
610
594
----
611
- ====
612
595
613
596
It is expected that implementations obtain a valid `JobExecution` from the
614
597
`JobRepository` and execute the `Job`.
@@ -647,7 +630,6 @@ Many of the domain concepts listed previously need to be configured in a Spring
647
630
use in a standard bean definition, a namespace has been provided for ease of
648
631
configuration, as the following example shows:
649
632
650
- ====
651
633
[source, xml, role="xmlContent"]
652
634
----
653
635
<beans:beans xmlns="http://www.springframework.org/schema/batch"
@@ -669,7 +651,6 @@ xsi:schemaLocation="
669
651
670
652
</beans:beans>
671
653
----
672
- ====
673
654
674
655
[role="xmlContent"]
675
656
As long as the batch namespace has been declared, any of its elements can be used. You can find more
0 commit comments