Add ability to use bean names by default for jobs and steps
Resolves #4858
This commit is contained in:
@@ -31,7 +31,17 @@ import org.springframework.batch.core.repository.JobRepository;
|
||||
public class JobBuilder extends JobBuilderHelper<JobBuilder> {
|
||||
|
||||
/**
|
||||
* Create a new builder for a job with the given name.
|
||||
* Create a new builder for a job with the given job repository. The name of the job
|
||||
* will be set to the bean name by default.
|
||||
* @param jobRepository the job repository to which the job should report to.
|
||||
* @since 6.0
|
||||
*/
|
||||
public JobBuilder(JobRepository jobRepository) {
|
||||
super(jobRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder for a job with the given name and job repository.
|
||||
* @param name the name of the job
|
||||
* @param jobRepository the job repository to which the job should report to
|
||||
* @since 5.0
|
||||
|
||||
@@ -54,6 +54,16 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
|
||||
private final CommonJobProperties properties;
|
||||
|
||||
/**
|
||||
* Create a new {@link JobBuilderHelper}.
|
||||
* @param jobRepository the job repository
|
||||
* @since 6.0
|
||||
*/
|
||||
public JobBuilderHelper(JobRepository jobRepository) {
|
||||
this.properties = new CommonJobProperties();
|
||||
properties.jobRepository = jobRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link JobBuilderHelper}.
|
||||
* @param name the job name
|
||||
@@ -229,6 +239,8 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
|
||||
public static class CommonJobProperties {
|
||||
|
||||
private String name;
|
||||
|
||||
private Set<JobExecutionListener> jobExecutionListeners = new LinkedHashSet<>();
|
||||
|
||||
private boolean restartable = true;
|
||||
@@ -336,8 +348,6 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
this.restartable = restartable;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2024 the original author or authors.
|
||||
* Copyright 2006-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -94,7 +94,6 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(name != null, "A Step must have a name");
|
||||
Assert.state(jobRepository != null, "JobRepository is mandatory");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,16 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
*/
|
||||
public class StepBuilder extends StepBuilderHelper<StepBuilder> {
|
||||
|
||||
/**
|
||||
* Initialize a step builder for a step with the given job repository. The name of the
|
||||
* step will be set to the bean name by default.
|
||||
* @param jobRepository the job repository to which the step should report to.
|
||||
* @since 6.0
|
||||
*/
|
||||
public StepBuilder(JobRepository jobRepository) {
|
||||
super(jobRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a step builder for a step with the given name and job repository.
|
||||
* @param name the name of the step
|
||||
|
||||
@@ -53,6 +53,16 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
|
||||
protected final CommonStepProperties properties;
|
||||
|
||||
/**
|
||||
* Create a new {@link StepBuilderHelper} with the given job repository.
|
||||
* @param jobRepository the job repository
|
||||
* @since 6.0
|
||||
*/
|
||||
public StepBuilderHelper(JobRepository jobRepository) {
|
||||
this.properties = new CommonStepProperties();
|
||||
properties.jobRepository = jobRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link StepBuilderHelper}.
|
||||
* @param name the step name
|
||||
@@ -176,6 +186,8 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
|
||||
public static class CommonStepProperties {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<StepExecutionListener> stepExecutionListeners = new ArrayList<>();
|
||||
|
||||
private int startLimit = Integer.MAX_VALUE;
|
||||
@@ -272,8 +284,6 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
this.allowStartIfComplete = allowStartIfComplete;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user