Skip to content

Commit 26158c1

Browse files
committed
Add default order for JobLauncherCommandLineRunner
Closes gh-2943
1 parent 4e88db9 commit 26158c1

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.boot.CommandLineRunner;
4545
import org.springframework.context.ApplicationEventPublisher;
4646
import org.springframework.context.ApplicationEventPublisherAware;
47+
import org.springframework.core.Ordered;
4748
import org.springframework.util.PatternMatchUtils;
4849
import org.springframework.util.StringUtils;
4950

@@ -56,7 +57,12 @@
5657
* @author Jean-Pierre Bergamin
5758
*/
5859
public class JobLauncherCommandLineRunner
59-
implements CommandLineRunner, ApplicationEventPublisherAware {
60+
implements CommandLineRunner, Ordered, ApplicationEventPublisherAware {
61+
62+
/**
63+
* The default order for the command line runner.
64+
*/
65+
public static final int DEFAULT_ORDER = 0;
6066

6167
private static final Log logger = LogFactory
6268
.getLog(JobLauncherCommandLineRunner.class);
@@ -73,6 +79,8 @@ public class JobLauncherCommandLineRunner
7379

7480
private Collection<Job> jobs = Collections.emptySet();
7581

82+
private int order = DEFAULT_ORDER;
83+
7684
private ApplicationEventPublisher publisher;
7785

7886
public JobLauncherCommandLineRunner(JobLauncher jobLauncher,
@@ -81,8 +89,13 @@ public JobLauncherCommandLineRunner(JobLauncher jobLauncher,
8189
this.jobExplorer = jobExplorer;
8290
}
8391

84-
public void setJobNames(String jobNames) {
85-
this.jobNames = jobNames;
92+
public void setOrder(int order) {
93+
this.order = order;
94+
}
95+
96+
@Override
97+
public int getOrder() {
98+
return this.order;
8699
}
87100

88101
@Override
@@ -95,6 +108,10 @@ public void setJobRegistry(JobRegistry jobRegistry) {
95108
this.jobRegistry = jobRegistry;
96109
}
97110

111+
public void setJobNames(String jobNames) {
112+
this.jobNames = jobNames;
113+
}
114+
98115
@Autowired(required = false)
99116
public void setJobParametersConverter(JobParametersConverter converter) {
100117
this.converter = converter;

0 commit comments

Comments
 (0)