Skip to content

Commit 499ec2b

Browse files
committed
Improve the documentation of scoped beans definition
Resolves #1502
1 parent 7b0e00e commit 499ec2b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

spring-batch-docs/asciidoc/step.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,3 +2510,27 @@ or partitioned steps. Spring Batch does not control the threads spawned in these
25102510
use cases, so it is not possible to set them up correctly to use such beans. Hence,
25112511
it is not recommended to use job-scoped beans in multi-threaded or partitioned steps.
25122512
====
2513+
2514+
[[scoping-item-streams]]
2515+
==== Scoping `ItemStream` components
2516+
2517+
When using the Java configuration style to define job or step scoped `ItemStream` beans,
2518+
the return type of the bean definition method should be at least `ItemStream`. This is required
2519+
so that Spring Batch correctly creates a proxy that implements this interface, and therefore
2520+
honors its contract by calling `open`, `update` and `close` methods as expected.
2521+
2522+
It is recommended to make the bean definition method of such beans return the most specific
2523+
known implementation, as shown in the following example:
2524+
2525+
.Define a step-scoped bean with the most specific return type
2526+
[source, java]
2527+
----
2528+
@Bean
2529+
@StepScope
2530+
public FlatFileItemReader flatFileItemReader(@Value("#{jobParameters['input.file.name']}") String name) {
2531+
return new FlatFileItemReaderBuilder<Foo>()
2532+
.resource(new FileSystemResource(name))
2533+
// set other properties of the item reader
2534+
.build();
2535+
}
2536+
----

0 commit comments

Comments
 (0)