diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobLocator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobLocator.java index 9e195e10b..8a840e0cc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobLocator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobLocator.java @@ -25,8 +25,10 @@ import org.springframework.lang.Nullable; * * @author Dave Syer * @author Mahmoud Ben Hassine - * + * @deprecated since 6.0 in favor of {@link JobRegistry}. Scheduled for removal in 6.2 or + * later. */ +@Deprecated(since = "6.0", forRemoval = true) public interface JobLocator { /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobRegistry.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobRegistry.java index c29ce74f4..f99fba1e9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobRegistry.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/JobRegistry.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.configuration; import java.util.Collection; import org.springframework.batch.core.Job; +import org.springframework.batch.core.launch.NoSuchJobException; /** * A runtime service registry interface for registering job configurations by @@ -27,7 +28,15 @@ import org.springframework.batch.core.Job; * @author Mahmoud Ben Hassine * */ -public interface JobRegistry extends JobLocator { +public interface JobRegistry { + + /** + * Returns a {@link Job} by name. + * @param name the name of the {@link Job} which should be unique + * @return a {@link Job} identified by the given name + * @throws NoSuchJobException if the required configuration can not be found. + */ + Job getJob(String name) throws NoSuchJobException; /** * Provides the currently registered job names. The return value is unmodifiable and diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java index 477316d41..5ffa134b6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java @@ -38,6 +38,7 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.JobParametersIncrementer; import org.springframework.batch.core.configuration.JobLocator; +import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.repository.explore.JobExplorer; @@ -74,7 +75,7 @@ import org.springframework.util.StringUtils; * can be used to load the job and its context from a single location. All dependencies of * the launcher will then be satisfied by autowiring by type from the combined application * context. Default values are provided for all fields except the {@link JobLauncher} and - * {@link JobLocator} . Therefore, if autowiring fails to set it (it should be noted that + * {@link JobRegistry} . Therefore, if autowiring fails to set it (it should be noted that * dependency checking is disabled because most of the fields have default values and thus * don't require dependencies to be fulfilled via autowiring) then an exception will be * thrown. It should also be noted that even if an exception is thrown by this class, it @@ -163,8 +164,8 @@ import org.springframework.util.StringUtils; * {@link BeanDefinitionStoreException} will be thrown. The same exception will also be * thrown if there is more than one present. Assuming the JobLauncher has been set * correctly, the jobIdentifier argument will be used to obtain an actual {@link Job}. If - * a {@link JobLocator} has been set, then it will be used, if not the beanFactory will be - * asked, using the jobIdentifier as the bean id. + * a {@link JobRegistry} has been set, then it will be used, if not the beanFactory will + * be asked, using the jobIdentifier as the bean id. *

* * @author Dave Syer @@ -183,6 +184,8 @@ public class CommandLineJobRunner { private JobLocator jobLocator; + private JobRegistry jobRegistry; + private static SystemExiter systemExiter = new JvmSystemExiter(); private static String message = ""; @@ -274,11 +277,22 @@ public class CommandLineJobRunner { /** * {@link JobLocator} to find a job to run. * @param jobLocator a {@link JobLocator} + * @deprecated since 6.0 in favor of {{@link #setJobRegistry(JobRegistry)}}. Scheduled + * for removal in 6.2 or later. */ + @Deprecated(since = "6.0", forRemoval = true) public void setJobLocator(JobLocator jobLocator) { this.jobLocator = jobLocator; } + /** + * Set the {@link JobRegistry}. + * @param jobRegistry a {@link JobRegistry} + */ + public void setJobRegistry(JobRegistry jobRegistry) { + this.jobRegistry = jobRegistry; + } + /* * Start a job by obtaining a combined classpath using the job launcher and job paths. * If a JobLocator has been set, then use it to obtain an actual job, if not ask the @@ -348,9 +362,9 @@ public class CommandLineJobRunner { } Job job = null; - if (jobLocator != null) { + if (jobRegistry != null) { try { - job = jobLocator.getJob(jobName); + job = jobRegistry.getJob(jobName); } catch (NoSuchJobException ignored) { }