Skip to content

MapJobRegistry registers discovered Jobs by their bean name instead of their job name #5122

@kzander91

Description

@kzander91

The changes made with #4855 ignore the names of the discovered Jobs:

@Override
public void afterSingletonsInstantiated() {
Map<String, Job> jobBeans = this.applicationContext.getBeansOfType(Job.class);
this.map.putAll(jobBeans);
}

We see that the bean names are used instead of Job#getName().
This should probably be changed to something like this:

	@Override
	public void afterSingletonsInstantiated() {
		this.applicationContext.getBeansOfType(Job.class).values().forEach(this::register);
	}

Since register() throws a checked exception, the exact logic may need to be changed a bit.


My workaround:

@Bean
MapJobRegistry jobRegistry(ObjectProvider<Job> jobs) {
    return new MapJobRegistry() {

        // Workaround for https://github.com/spring-projects/spring-batch/issues/5122
        @Override
        public void afterSingletonsInstantiated() {
            for (Job job : jobs) {
                try {
                    register(job);
                } catch (DuplicateJobException e) {
                    throw new IllegalStateException(e);
                }
            }
        }
    };
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions