Polish "Improve Spring Batch coverage in reference documentation"

See gh-19211
pull/19540/head
Stephane Nicoll 5 years ago
parent 6bd9b2ebc6
commit 5f987a67f8

@ -1525,6 +1525,7 @@
<jooq-version>${jooq.version}</jooq-version>
<spring-boot-version>${revision}</spring-boot-version>
<spring-amqp-version>${spring-amqp.version}</spring-amqp-version>
<spring-batch-version>${spring-batch.version}</spring-batch-version>
<spring-data-couchbase-version>${flattenedpom.version.org.springframework.data.spring-data-couchbase}</spring-data-couchbase-version>
<spring-data-commons-version>${flattenedpom.version.org.springframework.data.spring-data-commons}</spring-data-commons-version>
<spring-data-jpa-version>${flattenedpom.version.org.springframework.data.spring-data-jpa}</spring-data-jpa-version>

@ -53,7 +53,8 @@
:spring-amqp-api: https://docs.spring.io/spring-amqp/docs/{spring-amqp-version}/api/org/springframework/amqp
:spring-batch: https://spring.io/projects/spring-batch
:spring-batch-api: https://docs.spring.io/spring-batch/apidocs/org/springframework/batch
:spring-batch-api: https://docs.spring.io/spring-batch/docs/{spring-batch-version}/api/org/springframework/batch
:spring-batch-docs: https://docs.spring.io/spring-batch/docs/{spring-batch-version}/reference/html/
:spring-data: https://spring.io/projects/spring-data
:spring-data-cassandra: https://spring.io/projects/spring-data-cassandra
:spring-data-commons-api: https://docs.spring.io/spring-data/commons/docs/{spring-data-commons-version}/api/org/springframework/data

@ -2107,38 +2107,40 @@ The preceding example overrides the default factory, and it should be applied to
A number of questions often arise when people use Spring Batch from within a Spring Boot application.
This section addresses those questions.
[[howto-spring-batch-specifying-a-data-source]]
=== Specifying a Batch Data Source
By default, batch applications require a `DataSource` to store job details.
Batch autowires a single `DataSource` in your context and uses that for processing.
To have Batch use a `DataSource` other than the applications main `DataSource`, declare a `DataSource` bean, annotating its `@Bean` method with `@BatchDataSource`.
If you do so and want two data sources, remember to create another one and mark it as `@Primary`.
Spring Batch expects a single `DataSource` by default.
To have it use a `DataSource` other than the applications main `DataSource`, declare a `DataSource` bean, annotating its `@Bean` method with `@BatchDataSource`.
If you do so and want two data sources, remember to mark the other one `@Primary`.
To take greater control, implement `BatchConfigurer`.
See {spring-batch-api}/core/configuration/annotation/EnableBatchProcessing.html[The Javadoc of `@EnableBatchProcessing`] for more details.
For more about Spring Batch, see the {spring-batch}[Spring Batch project page].
For more info about Spring Batch, see the {spring-batch}[Spring Batch project page].
[[howto-running-spring-batch-jobs-on-startup]]
[[howto-spring-batch-running-jobs-on-startup]]
=== Running Spring Batch Jobs on Startup
Spring Batch auto-configuration is enabled by adding `@EnableBatchProcessing` (from Spring Batch) somewhere in your context.
Spring Batch auto-configuration is enabled by adding `@EnableBatchProcessing` to one of your `@Configuration` classes.
By default, it executes *all* `Jobs` in the application context on startup (see {spring-boot-autoconfigure-module-code}/batch/JobLauncherCommandLineRunner.java[`JobLauncherCommandLineRunner`] for details).
You can narrow down to a specific job or jobs by specifying `spring.batch.job.names` (which takes a comma-separated list of job name patterns).
See {spring-boot-autoconfigure-module-code}/batch/BatchAutoConfiguration.java[BatchAutoConfiguration] and https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java[@EnableBatchProcessing] for more details.
See {spring-boot-autoconfigure-module-code}/batch/BatchAutoConfiguration.java[BatchAutoConfiguration] and {spring-batch-api}/core/configuration/annotation/EnableBatchProcessing.html[@EnableBatchProcessing] for more details.
[[howto-spring-batch-running-command-line]]
=== Running from the Command Line
Running Spring Batch with Spring Boot from the command line differs from running Spring Batch by itself from the command line.
Spring Boot uses a class called `JobLaunchingCommandLineRunner`.
Spring Batch uses a class called `CommandLineJobRunner`.
They work a bit differently. However, for the most part, the differences do not cause trouble.
However, they parse command line arguments differently, which can cause trouble, as described in the next section.
The most important difference is that they parse command line arguments differently, which can cause trouble, as described in the next section.
==== Passing Command-line Arguments
==== Passing Command-line Arguments
Spring Boot uses `--` (two hyphens) to signal application arguments.
Spring Batch uses a single hyphen as a special marker on the `jobParameters` argument.
This section explains how to reconcile that difference when you use the `jobParameters` argument for Spring Batch within a Spring Boot application.
@ -2150,22 +2152,27 @@ However, in Spring Batch, putting a single `-` character before the `jobParamete
Best practice is to use the `jobParameters` value as the identifier for the `Job`, so this issue may cause problems.
To avoid the issue, you should generally use no `-` characters for the command-line options that you pass to Spring Boot on behalf of Spring Batch, as shown in the following example:
[source]
someParameter="someValue"
[source,properties,indent=0]
----
someParameter=someValue
----
However, if you mean to not use the `someValue` value as the identifier for the `Job`, use two hyphens, as shown in the following example:
However, if you mean to not use `someValue` value as the identifier for the `Job`, use two hyphens, as shown in the following example:
[source]
--jobParameters="someValue"
[source,properties,indent=0]
----
--jobParameters=someValue
----
In the second example, Spring Boot passes the parameter to Spring Batch as `-jobParameters="someValue"`, and `someValue` is used as a non-identifying job parameter.
[[howto-spring-batch-storing-job-repository]]
=== Storing the Job Repository
Spring Batch requires a memory store for the `Job` repository.
If you use Spring Boot, you must use an actual database. Note that it can be an in-memory database.
See https://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html#configuringJobRepository[Configuring a Job Repository].
Spring Batch requires a data store for the `Job` repository.
If you use Spring Boot, you must use an actual database.
Note that it can be an in-memory database, see {spring-batch-docs}job.html#configuringJobRepository[Configuring a Job Repository].

Loading…
Cancel
Save