Skip to content

Clarify ChunkListener changes in v6 #5226

@cho-heidi

Description

@cho-heidi

Bug description
After upgrading from Spring Batch 5.x to 6.x, ChunkListener callbacks are no longer invoked when defined on an ItemReader.
This affects both of the following approaches:
• Implementing ChunkListener directly on the ItemReader
• Using the @BeforeChunk annotation
Both approaches worked as expected in Spring Batch 5.x, but in Spring Batch 6.x neither beforeChunk nor methods annotated with @BeforeChunk are called.
The step itself executes normally and read() is invoked, but chunk lifecycle callbacks are silently skipped.
I could not find any mention of this behavioral change in the migration guide or reference documentation.

Environment
• Spring Batch version: 6.x
• Spring Boot version: 4.0.1
• Java version: 21
• Language: Kotlin

Steps to reproduce

  1. Create an ItemReader bean annotated with @StepScope
  2. Define chunk lifecycle logic using either:
    • ChunkListener#beforeChunk
    • a method annotated with @BeforeChunk
  3. Register the reader normally in a chunk-oriented step
  4. Run the job

Example Using ChunkListener

@Component
@StepScope
class TestReader() : ItemReader<Long>, ChunkListener<Long, Long> {
    private val logger = LoggerFactory.getLogger(this::class.simpleName)

    override fun beforeChunk(chunk: Chunk<Long>) {
           logger.info("before chunk") // never invoked in Spring Batch 6.x
    }

    override fun read(): Long? {
        return 10000L
    }
}

Expected behavior
Chunk lifecycle callbacks (beforeChunk, @BeforeChunk) should be invoked before each chunk, as they were in Spring Batch 5.x.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions