Skip to content

CommandLineJobOperator requires JobRegistry bean but it's no longer auto-configured #5026

@KILL9-NO-MERCY

Description

@KILL9-NO-MERCY

Hello Spring Batch team,

Thank you for all your great work on Spring Batch 6! I've been testing the milestone releases and came across what might be an issue or a documentation gap regarding CommandLineJobOperator and JobRegistry configuration.

Bug description
After #4971, JobRegistry was made optional and is no longer automatically registered as a bean in Spring Batch configuration.

However, CommandLineJobOperator (introduced in #4899) explicitly requires a JobRegistry bean from the ApplicationContext, causing it to fail with both @EnableBatchProcessing and DefaultBatchConfiguration.

Environment

  • Spring Batch version: 6.0.0-M4

Steps to reproduce / Minimal Complete Reproducible example
With DefaultBatchConfiguration:

@Configuration
public class BatchConfig extends DefaultBatchConfiguration {
    // No JobRegistry bean
}

Or with @EnableBatchProcessing:

@Configuration
@EnableBatchProcessing
public class BatchConfig {
    // No JobRegistry bean
}

Then run:

java CommandLineJobOperator my.package.BatchConfig start myJob

Result: Application fails with error.

Expected behavior
CommandLineJobOperator should work with the default Spring Batch configuration, or the documentation should clearly state that manual JobRegistry bean registration is required.

Actual behavior
Application fails with:

A required bean was not found in the application context: 
No qualifying bean of type 'org.springframework.batch.core.configuration.JobRegistry' available

Error location:
The error occurs in CommandLineJobOperator.main() at line 314:

public static void main(String[] args) {
    ...
    jobRegistry = context.getBean(JobRegistry.class);  // ← Fails here (line 314)
    ...
}

**Current Workaround**
Users must manually register `JobRegistry` as a bean:

**With `DefaultBatchConfiguration`:**
```java
@Configuration
public class BatchConfig extends DefaultBatchConfiguration {
    
    @Bean
    public JobRegistry jobRegistry() {
        return new MapJobRegistry();
    }
    
    @Override
    protected JobRegistry getJobRegistry() {
        return applicationContext.getBean(JobRegistry.class);
    }
}

Question
Is this the intended behavior? Since #4971 made JobRegistry optional, we're wondering if CommandLineJobOperator is expected to require manual JobRegistry bean registration, or if this is an unintended side effect.

If manual registration is the intended approach, it would be very helpful to have this documented with examples for both configuration styles (@EnableBatchProcessing and DefaultBatchConfiguration).

would appreciate any clarification on the expected usage pattern. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions