Skip to content

Commit d54fa25

Browse files
committed
Update documentation
1 parent 4a94689 commit d54fa25

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

spring-batch-docs/src/main/asciidoc/job.adoc

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Job footballJob(JobRepository jobRepository) {
4848

4949
[role="javaContent"]
5050
A `Job` (and, typically, any `Step` within it) requires a `JobRepository`. The
51-
configuration of the `JobRepository` is handled through the <<job.adoc#javaConfig,`BatchConfigurer`>>.
51+
configuration of the `JobRepository` is handled through the <<job.adoc#javaConfig,`Java Configuration`>>.
5252

5353
[role="javaContent"]
5454
The preceding example illustrates a `Job` that consists of three `Step` instances. The job related
@@ -444,13 +444,14 @@ annotation and two builders.
444444

445445
The `@EnableBatchProcessing` annotation works similarly to the other `@Enable*` annotations in the
446446
Spring family. In this case, `@EnableBatchProcessing` provides a base configuration for
447-
building batch jobs. Within this base configuration, an instance of `StepScope` and `Jobscope` are
447+
building batch jobs. Within this base configuration, an instance of `StepScope` and `JobScope` are
448448
created, in addition to a number of beans being made available to be autowired:
449449

450450
* `JobRepository`: a bean named `jobRepository`
451451
* `JobLauncher`: a bean named `jobLauncher`
452452
* `JobRegistry`: a bean named `jobRegistry`
453453
* `JobExplorer`: a bean named `jobExplorer`
454+
* `JobOperator`: a bean named `jobOperator`
454455

455456
The default implementation provides the beans mentioned in the preceding list and requires a `DataSource`
456457
and a `PlatformTransactionManager` to be provided as beans within the context. The data source and transaction
@@ -1313,9 +1314,9 @@ The following example shows how to configure a `JobExplorer` in Java:
13131314
[source, java, role="javaContent"]
13141315
----
13151316
...
1316-
// This would reside in your BatchConfigurer implementation
1317-
@Override
1318-
public JobExplorer getJobExplorer() throws Exception {
1317+
// This would reside in your DefaultBatchConfiguration extension
1318+
@Bean
1319+
public JobExplorer jobExplorer() throws Exception {
13191320
JobExplorerFactoryBean factoryBean = new JobExplorerFactoryBean();
13201321
factoryBean.setDataSource(this.dataSource);
13211322
return factoryBean.getObject();
@@ -1348,9 +1349,9 @@ The following example shows how to set the table prefix for a `JobExplorer` in J
13481349
[source, java, role="javaContent"]
13491350
----
13501351
...
1351-
// This would reside in your BatchConfigurer implementation
1352-
@Override
1353-
public JobExplorer getJobExplorer() throws Exception {
1352+
// This would reside in your DefaultBatchConfiguration extension
1353+
@Bean
1354+
public JobExplorer jobExplorer() throws Exception {
13541355
JobExplorerFactoryBean factoryBean = new JobExplorerFactoryBean();
13551356
factoryBean.setDataSource(this.dataSource);
13561357
factoryBean.setTablePrefix("SYSTEM.");
@@ -1389,7 +1390,7 @@ The following example shows how to configure your own `JobRegistry`:
13891390
----
13901391
...
13911392
// This is already provided via the @EnableBatchProcessing but can be customized via
1392-
// overriding the getter in the SimpleBatchConfiguration
1393+
// overriding the bean in the DefaultBatchConfiguration
13931394
@Override
13941395
@Bean
13951396
public JobRegistry jobRegistry() throws Exception {
@@ -1430,9 +1431,9 @@ defined in Java:
14301431
[source, java, role="javaContent"]
14311432
----
14321433
@Bean
1433-
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor() {
1434+
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
14341435
JobRegistryBeanPostProcessor postProcessor = new JobRegistryBeanPostProcessor();
1435-
postProcessor.setJobRegistry(jobRegistry());
1436+
postProcessor.setJobRegistry(jobRegistry);
14361437
return postProcessor;
14371438
}
14381439
----
@@ -1615,7 +1616,6 @@ The following example shows a typical bean definition for `SimpleJobOperator` in
16151616
JobLauncher jobLauncher) {
16161617
16171618
SimpleJobOperator jobOperator = new SimpleJobOperator();
1618-
16191619
jobOperator.setJobExplorer(jobExplorer);
16201620
jobOperator.setJobRepository(jobRepository);
16211621
jobOperator.setJobRegistry(jobRegistry);
@@ -1626,6 +1626,9 @@ The following example shows a typical bean definition for `SimpleJobOperator` in
16261626
----
16271627
====
16281628

1629+
As of version 5.0, the `@EnableBatchProcessing` annotation automatically registers a job operator bean
1630+
in the application context.
1631+
16291632
NOTE: If you set the table prefix on the job repository, do not forget to set it on the job explorer as well.
16301633

16311634
[[JobParametersIncrementer]]

spring-batch-docs/src/main/asciidoc/monitoring-and-metrics.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ under the `spring.batch` prefix. The following table explains all the metrics in
2222
|`spring.batch.job`|`TIMER`|Duration of job execution|`name`, `status`
2323
|`spring.batch.job.active`|`LONG_TASK_TIMER`|Currently active jobs|`name`
2424
|`spring.batch.step`|`TIMER`|Duration of step execution|`name`, `job.name`, `status`
25+
|`spring.batch.step.active`|`LONG_TASK_TIMER`|Currently active step|`name`
2526
|`spring.batch.item.read`|`TIMER`|Duration of item reading|`job.name`, `step.name`, `status`
2627
|`spring.batch.item.process`|`TIMER`|Duration of item processing|`job.name`, `step.name`, `status`
2728
|`spring.batch.chunk.write`|`TIMER`|Duration of chunk writing|`job.name`, `step.name`, `status`
@@ -84,3 +85,13 @@ Metrics.globalRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("spri
8485

8586
See Micrometer's link:$$http://micrometer.io/docs/concepts#_meter_filters$$[reference documentation]
8687
for more details.
88+
89+
[[tracing]]
90+
== Tracing
91+
92+
As of version 5, Spring Batch provides tracing through Micrometer's `Observation` API. By default, tracing is enabled
93+
when using `@EnableBatchProcessing`. Spring Batch will create a trace for each job execution and a span for each
94+
step execution.
95+
96+
If you do not use `EnableBatchProcessing`, you need to register a `BatchObservabilityBeanPostProcessor` in your
97+
application context, which will automatically setup Micrometer's observability in your jobs and steps beans.

spring-batch-docs/src/main/asciidoc/testing.adoc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ JUnit facilities
2727
* `@SpringBatchTest` injects Spring Batch test utilities (such as the
2828
`JobLauncherTestUtils` and `JobRepositoryTestUtils`) in the test context
2929

30-
NOTE: Note that `JobRepositoryTestUtils` requires a `DataSource` bean. Since
31-
`@SpringBatchTest` registers a `JobRepositoryTestUtils` in the test
32-
context, it is expected that the test context contains a single autowire candidate
33-
for a `DataSource` (either a single bean definition or one that is
34-
annotated with `org.springframework.context.annotation.Primary`).
30+
NOTE: If the test context contains a single `Job` bean definition, this
31+
bean will be autowired in `JobLauncherTestUtils`. Otherwise, the job
32+
under test should be manually set on the `JobLauncherTestUtils`.
3533

3634
[role="javaContent"]
3735
The following Java example shows the annotations in use:

spring-batch-docs/src/main/asciidoc/whatsnew.adoc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:toc: left
33
:toclevels: 4
44

5-
This section shows the major highlights of Spring Batch 5 and is not an exhaustive list of changes.
5+
This section shows the major highlights of Spring Batch 5.
66
For more details,
77
please refer to the link:$$https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide$$[migration guide].
88

@@ -262,6 +262,16 @@ customizing the transaction attributes.
262262
The same transaction support was added to the `JobOperator` through a new factory bean
263263
named `JobOperatorFactoryBean`.
264264

265+
==== Automatic registration of a JobOperator with EnableBatchProcessing
266+
267+
As of version 4, the `EnableBatchProcessing` annotation provided all the basic infrastructure
268+
beans that are required to launch Spring Batch jobs. However, it did not register a job
269+
operator bean, which is the main entry point to stop, restart and abandon job executions.
270+
271+
While these utilities are not used as often as launching jobs, adding a job operator automatically
272+
in the application context can be useful to avoid a manual configuration of such a bean
273+
by end users.
274+
265275
==== Improved Java records support
266276

267277
The support for Java records as items in a chunk-oriented step has initially been introduced in v4.3,

0 commit comments

Comments
 (0)