You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java
+7-8Lines changed: 7 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -45,15 +45,14 @@
45
45
importorg.springframework.util.StringUtils;
46
46
47
47
/**
48
-
* {@link EnableAutoConfiguration Auto-configuration} for Spring Batch. By default a
49
-
* Runner will be created and all jobs in the context will be executed on startup.
48
+
* {@link EnableAutoConfiguration Auto-configuration} for Spring Batch. If a single job is
49
+
* found in the context, it will be executed on startup.
50
50
* <p>
51
51
* Disable this behavior with {@literal spring.batch.job.enabled=false}).
52
52
* <p>
53
-
* Alternatively, discrete Job names to execute on startup can be supplied by the User
54
-
* with a comma-delimited list: {@literal spring.batch.job.names=job1,job2}. In this case
55
-
* the Runner will first find jobs registered as Beans, then those in the existing
56
-
* JobRegistry.
53
+
* If multiple jobs are found, a job name to execute on startup can be supplied by the
54
+
* User with : {@literal spring.batch.job.name=job1}. In this case the Runner will first
55
+
* find jobs registered as Beans, then those in the existing JobRegistry.
57
56
*
58
57
* @author Dave Syer
59
58
* @author Eddú Meléndez
@@ -74,9 +73,9 @@ public class BatchAutoConfiguration {
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -46,17 +46,17 @@ public Jdbc getJdbc() {
46
46
publicstaticclassJob {
47
47
48
48
/**
49
-
* Comma-separated list of job names to execute on startup (for instance,
50
-
* 'job1,job2'). By default, all Jobs found in the context are executed.
49
+
* Job name to execute on startup. Must be specified if multiple Jobs are found in
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java
+20-18Lines changed: 20 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@
24
24
importjava.util.Map;
25
25
importjava.util.Properties;
26
26
27
+
importjakarta.annotation.PostConstruct;
27
28
importorg.apache.commons.logging.Log;
28
29
importorg.apache.commons.logging.LogFactory;
29
30
@@ -53,7 +54,6 @@
53
54
importorg.springframework.core.Ordered;
54
55
importorg.springframework.core.log.LogMessage;
55
56
importorg.springframework.util.Assert;
56
-
importorg.springframework.util.PatternMatchUtils;
57
57
importorg.springframework.util.StringUtils;
58
58
59
59
/**
@@ -86,7 +86,7 @@ public class JobLauncherApplicationRunner implements ApplicationRunner, Ordered,
86
86
87
87
privateJobRegistryjobRegistry;
88
88
89
-
privateStringjobNames;
89
+
privateStringjobName;
90
90
91
91
privateCollection<Job> jobs = Collections.emptySet();
92
92
@@ -110,6 +110,13 @@ public JobLauncherApplicationRunner(JobLauncher jobLauncher, JobExplorer jobExpl
110
110
this.jobRepository = jobRepository;
111
111
}
112
112
113
+
@PostConstruct
114
+
publicvoidvalidate() {
115
+
if (this.jobs.size() > 1 && !StringUtils.hasText(this.jobName)) {
116
+
thrownewIllegalArgumentException("Job name must be specified in case of multiple jobs");
117
+
}
118
+
}
119
+
113
120
publicvoidsetOrder(intorder) {
114
121
this.order = order;
115
122
}
@@ -129,8 +136,8 @@ public void setJobRegistry(JobRegistry jobRegistry) {
0 commit comments