-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Description
The changes made with #4855 ignore the names of the discovered Jobs:
Lines 63 to 67 in fa73e01
| @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);
}
}
}
};
}