Deprecate JobLocator in favor of JobRegistry

Related to #4847
This commit is contained in:
Mahmoud Ben Hassine
2025-06-09 13:30:49 +02:00
parent 8fbda369a8
commit c872a12ad5
3 changed files with 32 additions and 7 deletions

View File

@@ -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 {
/**

View File

@@ -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

View File

@@ -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.
* </p>
*
* @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) {
}