Java Reference
In-Depth Information
With the common components defined, let's go back to basicJob.xml . With regard to configuration,
90% of the configuration of a job is the ordered definition of the steps, which is covered later in this
chapter. Note about the basicJob that you haven't configured any reference to a job repository or a
transaction manager. This is because by default, Spring uses the jobRepository with the name
jobRepository and the transaction manager named transactionManager . You see how to specifically
configure these elements in Chapter 5, which discusses using JobRepository and its metadata.
Job Inheritance
Most of the options related to configuring a job are related to execution, so you see those later when you
cover job execution. However, there is one instance when you can alter the job configuration that makes
sense to discuss here: the use of inheritance.
Like most other object-oriented aspects of programming, the Spring Batch framework allows you to
configure common aspects of your jobs once and then extend the base job with other jobs. Those other
jobs inherit the properties of the job they're extending. But there are some caveats to inheritance in
Spring Batch. Spring Batch allows the inheritance of all job-level configurations from job to job. This is
an important point. You can't define a job that has common steps you can inherit. Things you're allowed
to inherit are the ability to restart a job, job listeners, and a validator for any parameters passed in. To do
so, you do two things: declare the parent job abstract and specify it as the parent job in any job that
wants to inherit functionality from it.
Listing 4-3 configures a parent job to be restartable 4 and then extends it with sampleJob . Because
sampleJob extends baseJob , it's also restartable. Listing 4-4 shows how you can configure an abstract job
that has a parameter validator configured and extend it to inherit the validator as well.
Listing 4-3. inheritanceJob.xml with Job Inheritance
<job id="baseJob" abstract="true" restartable="true">
</job>
<job id="inheritanceJob" parent="baseJob">
...
</job>
Listing 4-4. Parameter Validator Inheritance
<job id="baseJob" abstract="true" restartable="true">
<validator ref="myParameterValidator"/>
</job>
<job id="sampleJob1" parent="baseJob">
...
</job>
Although most of a job's configuration can be inherited from a parent job, not all of it is. Following
is a list of the things you can define in a parent job that are inherited by its children:
Restartable: Specifies whether a job is restartable or not
4 Restartability is covered in greater detail in Chapter 6.
 
Search WWH ::




Custom Search