Skip to content

Commit be231f7

Browse files
committed
Improve the documentation of scoped beans definition
Resolves #1502
1 parent 27a8ed7 commit be231f7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -2492,3 +2492,27 @@ NOTE: There are some practical limitations of using job-scoped beans in multi-th
24922492
or partitioned steps. Spring Batch does not control the threads spawned in these
24932493
use cases, so it is not possible to set them up correctly to use such beans. Hence,
24942494
we do not recommend using job-scoped beans in multi-threaded or partitioned steps.
2495+
2496+
[[scoping-item-streams]]
2497+
==== Scoping `ItemStream` components
2498+
2499+
When using the Java configuration style to define job or step scoped `ItemStream` beans,
2500+
the return type of the bean definition method should be at least `ItemStream`. This is required
2501+
so that Spring Batch correctly creates a proxy that implements this interface, and therefore
2502+
honors its contract by calling `open`, `update` and `close` methods as expected.
2503+
2504+
It is recommended to make the bean definition method of such beans return the most specific
2505+
known implementation, as shown in the following example:
2506+
2507+
.Define a step-scoped bean with the most specific return type
2508+
[source, java]
2509+
----
2510+
@Bean
2511+
@StepScope
2512+
public FlatFileItemReader flatFileItemReader(@Value("#{jobParameters['input.file.name']}") String name) {
2513+
return new FlatFileItemReaderBuilder<Foo>()
2514+
.resource(new FileSystemResource(name))
2515+
// set other properties of the item reader
2516+
.build();
2517+
}
2518+
----

0 commit comments

Comments
 (0)