Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c872a12

Browse files
Deprecate JobLocator in favor of JobRegistry
Related to #4847
1 parent 8fbda36 commit c872a12

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

‎spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobLocator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
*
2626
* @author Dave Syer
2727
* @author Mahmoud Ben Hassine
28-
*
28+
* @deprecated since 6.0 in favor of {@link JobRegistry}. Scheduled for removal in 6.2 or
29+
* later.
2930
*/
31+
@Deprecated(since = "6.0", forRemoval = true)
3032
public interface JobLocator {
3133

3234
/**

‎spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobRegistry.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collection;
1919

2020
import org.springframework.batch.core.Job;
21+
import org.springframework.batch.core.launch.NoSuchJobException;
2122

2223
/**
2324
* A runtime service registry interface for registering job configurations by
@@ -27,7 +28,15 @@
2728
* @author Mahmoud Ben Hassine
2829
*
2930
*/
30-
public interface JobRegistry extends JobLocator {
31+
public interface JobRegistry {
32+
33+
/**
34+
* Returns a {@link Job} by name.
35+
* @param name the name of the {@link Job} which should be unique
36+
* @return a {@link Job} identified by the given name
37+
* @throws NoSuchJobException if the required configuration can not be found.
38+
*/
39+
Job getJob(String name) throws NoSuchJobException;
3140

3241
/**
3342
* Provides the currently registered job names. The return value is unmodifiable and

‎spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.batch.core.JobParametersBuilder;
3939
import org.springframework.batch.core.JobParametersIncrementer;
4040
import org.springframework.batch.core.configuration.JobLocator;
41+
import org.springframework.batch.core.configuration.JobRegistry;
4142
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
4243
import org.springframework.batch.core.converter.JobParametersConverter;
4344
import org.springframework.batch.core.repository.explore.JobExplorer;
@@ -74,7 +75,7 @@
7475
* can be used to load the job and its context from a single location. All dependencies of
7576
* the launcher will then be satisfied by autowiring by type from the combined application
7677
* context. Default values are provided for all fields except the {@link JobLauncher} and
77-
* {@link JobLocator} . Therefore, if autowiring fails to set it (it should be noted that
78+
* {@link JobRegistry} . Therefore, if autowiring fails to set it (it should be noted that
7879
* dependency checking is disabled because most of the fields have default values and thus
7980
* don't require dependencies to be fulfilled via autowiring) then an exception will be
8081
* thrown. It should also be noted that even if an exception is thrown by this class, it
@@ -163,8 +164,8 @@
163164
* {@link BeanDefinitionStoreException} will be thrown. The same exception will also be
164165
* thrown if there is more than one present. Assuming the JobLauncher has been set
165166
* correctly, the jobIdentifier argument will be used to obtain an actual {@link Job}. If
166-
* a {@link JobLocator} has been set, then it will be used, if not the beanFactory will be
167-
* asked, using the jobIdentifier as the bean id.
167+
* a {@link JobRegistry} has been set, then it will be used, if not the beanFactory will
168+
* be asked, using the jobIdentifier as the bean id.
168169
* </p>
169170
*
170171
* @author Dave Syer
@@ -183,6 +184,8 @@ public class CommandLineJobRunner {
183184

184185
private JobLocator jobLocator;
185186

187+
private JobRegistry jobRegistry;
188+
186189
private static SystemExiter systemExiter = new JvmSystemExiter();
187190

188191
private static String message = "";
@@ -274,11 +277,22 @@ public void exit(int status) {
274277
/**
275278
* {@link JobLocator} to find a job to run.
276279
* @param jobLocator a {@link JobLocator}
280+
* @deprecated since 6.0 in favor of {{@link #setJobRegistry(JobRegistry)}}. Scheduled
281+
* for removal in 6.2 or later.
277282
*/
283+
@Deprecated(since = "6.0", forRemoval = true)
278284
public void setJobLocator(JobLocator jobLocator) {
279285
this.jobLocator = jobLocator;
280286
}
281287

288+
/**
289+
* Set the {@link JobRegistry}.
290+
* @param jobRegistry a {@link JobRegistry}
291+
*/
292+
public void setJobRegistry(JobRegistry jobRegistry) {
293+
this.jobRegistry = jobRegistry;
294+
}
295+
282296
/*
283297
* Start a job by obtaining a combined classpath using the job launcher and job paths.
284298
* If a JobLocator has been set, then use it to obtain an actual job, if not ask the
@@ -348,9 +362,9 @@ int start(String jobPath, String jobIdentifier, String[] parameters, Set<String>
348362
}
349363

350364
Job job = null;
351-
if (jobLocator != null) {
365+
if (jobRegistry != null) {
352366
try {
353-
job = jobLocator.getJob(jobName);
367+
job = jobRegistry.getJob(jobName);
354368
}
355369
catch (NoSuchJobException ignored) {
356370
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /