File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
spring-batch-docs/asciidoc Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2510,3 +2510,27 @@ or partitioned steps. Spring Batch does not control the threads spawned in these
2510
2510
use cases, so it is not possible to set them up correctly to use such beans. Hence,
2511
2511
it is not recommended to use job-scoped beans in multi-threaded or partitioned steps.
2512
2512
====
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
+ ----
You can’t perform that action at this time.
0 commit comments