From bfe487ccccfd2b5d7f82b07386094fdaaddd06c1 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Thu, 12 Jun 2025 08:25:03 +0200 Subject: [PATCH] Deprecate redundant APIs This commit deprecates redundant APIs to simplify the way to configure and use Spring Batch. The most notable changes are: - JobLauncher is deprecated in favor of JobOperator - JobExplorer is deprecated in favor of JobRepository - CommandLineJobRunner is deprecated in favor of more modern alternatives like Spring Boot's job Launcher Other APIs that are only used in the newly deprecated APIs have been deprecated as well. Resolves #4847 --- .../batch/core/launch/JobLauncher.java | 3 +++ .../core/launch/support/CommandLineJobRunner.java | 11 +++++------ .../batch/core/launch/support/JvmSystemExiter.java | 4 +++- .../launch/support/RuntimeExceptionTranslator.java | 5 ++++- .../batch/core/launch/support/SystemExiter.java | 4 +++- .../core/launch/support/TaskExecutorJobLauncher.java | 3 +++ .../batch/core/repository/explore/JobExplorer.java | 4 ++++ .../support/AbstractJobExplorerFactoryBean.java | 5 ++++- .../explore/support/JdbcJobExplorerFactoryBean.java | 5 ++++- .../explore/support/JobExplorerFactoryBean.java | 4 ++-- .../explore/support/MongoJobExplorerFactoryBean.java | 4 ++++ .../repository/explore/support/SimpleJobExplorer.java | 4 ++++ .../resource/StepExecutionSimpleCompletionPolicy.java | 3 +++ .../batch/support/PropertiesConverter.java | 5 ++++- 14 files changed, 50 insertions(+), 14 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobLauncher.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobLauncher.java index 79afede5c..d7b43efed 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobLauncher.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobLauncher.java @@ -34,8 +34,11 @@ import org.springframework.batch.core.repository.JobRestartException; * @author Dave Syer * @author Taeik Lim * @author Mahmoud Ben Hassine + * + * @deprecated since 6.0 in favor of {@link JobOperator}. Scheduled for removal in 6.2 or later. */ @FunctionalInterface +@Deprecated(since = "6.0", forRemoval = true) public interface JobLauncher { /** 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 5ffa134b6..b32d2a7ae 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 @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,12 +41,8 @@ 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.launch.*; import org.springframework.batch.core.repository.explore.JobExplorer; -import org.springframework.batch.core.launch.JobExecutionNotFailedException; -import org.springframework.batch.core.launch.JobExecutionNotRunningException; -import org.springframework.batch.core.launch.JobExecutionNotStoppedException; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.launch.NoSuchJobException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -173,7 +169,10 @@ import org.springframework.util.StringUtils; * @author Mahmoud Ben Hassine * @author Minsoo Kim * @since 1.0 + * + * @deprecated since 6.0 with no replacement. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class CommandLineJobRunner { protected static final Log logger = LogFactory.getLog(CommandLineJobRunner.class); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JvmSystemExiter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JvmSystemExiter.java index b0d9e855f..1df6ba190 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JvmSystemExiter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JvmSystemExiter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,9 @@ package org.springframework.batch.core.launch.support; * @author Lucas Ward * @author Dave Syer * + * @deprecated since 6.0 with no replacement. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class JvmSystemExiter implements SystemExiter { /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/RuntimeExceptionTranslator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/RuntimeExceptionTranslator.java index cc0e3536d..218dd42fb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/RuntimeExceptionTranslator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/RuntimeExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,11 @@ import org.aopalliance.intercept.MethodInvocation; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * + * @deprecated since 6.0 with no replacement, for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class RuntimeExceptionTranslator implements MethodInterceptor { @Override diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SystemExiter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SystemExiter.java index a94c8b116..87bf35565 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SystemExiter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SystemExiter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,9 @@ package org.springframework.batch.core.launch.support; * * @author Lucas Ward * + * @deprecated since 6.0 with no replacement. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public interface SystemExiter { /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/TaskExecutorJobLauncher.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/TaskExecutorJobLauncher.java index f6994472f..1d3ccc1cd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/TaskExecutorJobLauncher.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/TaskExecutorJobLauncher.java @@ -65,7 +65,10 @@ import org.springframework.util.Assert; * @since 1.0 * @see JobRepository * @see TaskExecutor + * + * @deprecated since 6.0 in favor of {@link TaskExecutorJobOperator}. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class TaskExecutorJobLauncher implements JobLauncher, InitializingBean { protected static final Log logger = LogFactory.getLog(TaskExecutorJobLauncher.class); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/JobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/JobExplorer.java index afbe42c70..e47ceddc7 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/JobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/JobExplorer.java @@ -24,6 +24,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.launch.NoSuchJobException; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.item.ExecutionContext; import org.springframework.lang.Nullable; @@ -38,7 +39,10 @@ import org.springframework.lang.Nullable; * @author Mahmoud Ben Hassine * @author Parikshit Dutta * @since 2.0 + * + * @deprecated since 6.0 in favor of {@link JobRepository}. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public interface JobExplorer { /* diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/AbstractJobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/AbstractJobExplorerFactoryBean.java index a2d1eb55b..76712d806 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/AbstractJobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/AbstractJobExplorerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,10 @@ import org.springframework.util.Assert; * @author Dave Syer * @author Mahmoud Ben Hassine * @since 2.0 + * + * @deprecated since 6.0 with no replacement. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public abstract class AbstractJobExplorerFactoryBean implements FactoryBean, InitializingBean { private static final String TRANSACTION_ISOLATION_LEVEL_PREFIX = "ISOLATION_"; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JdbcJobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JdbcJobExplorerFactoryBean.java index 7fe27bb46..a90ec992f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JdbcJobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JdbcJobExplorerFactoryBean.java @@ -16,6 +16,7 @@ package org.springframework.batch.core.repository.explore.support; +import org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean; import org.springframework.beans.factory.FactoryBean; /** @@ -25,9 +26,11 @@ import org.springframework.beans.factory.FactoryBean; * * @author Dave Syer * @author Mahmoud Ben Hassine - * @since 6.0 + * + * @deprecated since 6.0 in favor of {@link JdbcJobRepositoryFactoryBean}. Scheduled for removal in 6.2 or later. */ @SuppressWarnings("removal") +@Deprecated(since = "6.0", forRemoval = true) public class JdbcJobExplorerFactoryBean extends JobExplorerFactoryBean { } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JobExplorerFactoryBean.java index 10cbc3ac0..3809cf409 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/JobExplorerFactoryBean.java @@ -42,6 +42,7 @@ import org.springframework.batch.core.repository.dao.jdbc.JdbcStepExecutionDao; import org.springframework.batch.core.repository.dao.JobExecutionDao; import org.springframework.batch.core.repository.dao.JobInstanceDao; import org.springframework.batch.core.repository.dao.StepExecutionDao; +import org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.support.ConfigurableConversionService; @@ -61,8 +62,7 @@ import org.springframework.util.Assert; * @author Dave Syer * @author Mahmoud Ben Hassine * @since 2.0 - * @deprecated Since 6.0 and scheduled for removal in 6.2 in favor of using - * {@link JdbcJobExplorerFactoryBean}. + * @deprecated since 6.0 in favor of {@link JdbcJobRepositoryFactoryBean}. Scheduled for removal in 6.2 or later. */ @Deprecated(since = "6.0", forRemoval = true) public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean implements InitializingBean { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/MongoJobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/MongoJobExplorerFactoryBean.java index 053147ff7..0a0f098e2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/MongoJobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/MongoJobExplorerFactoryBean.java @@ -23,6 +23,7 @@ import org.springframework.batch.core.repository.dao.mongodb.MongoExecutionConte import org.springframework.batch.core.repository.dao.mongodb.MongoJobExecutionDao; import org.springframework.batch.core.repository.dao.mongodb.MongoJobInstanceDao; import org.springframework.batch.core.repository.dao.mongodb.MongoStepExecutionDao; +import org.springframework.batch.core.repository.support.MongoJobRepositoryFactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.convert.MappingMongoConverter; @@ -38,7 +39,10 @@ import org.springframework.util.Assert; * * @author Mahmoud Ben Hassine * @since 5.2.0 + * + * @deprecated since 6.0 in favor of {@link MongoJobRepositoryFactoryBean}. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class MongoJobExplorerFactoryBean extends AbstractJobExplorerFactoryBean implements InitializingBean { private MongoOperations mongoOperations; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/SimpleJobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/SimpleJobExplorer.java index 1b99c29ac..2a621c53f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/SimpleJobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/SimpleJobExplorer.java @@ -26,6 +26,7 @@ import org.springframework.batch.core.repository.dao.ExecutionContextDao; import org.springframework.batch.core.repository.dao.JobExecutionDao; import org.springframework.batch.core.repository.dao.JobInstanceDao; import org.springframework.batch.core.repository.dao.StepExecutionDao; +import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.item.ExecutionContext; import org.springframework.lang.Nullable; @@ -47,7 +48,10 @@ import java.util.Set; * @see JobExecutionDao * @see StepExecutionDao * @since 2.0 + * + * @deprecated since 6.0 in favor of {@link SimpleJobRepository}. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class SimpleJobExplorer implements JobExplorer { protected JobInstanceDao jobInstanceDao; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java index 6625b2fe6..be275b228 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java @@ -44,7 +44,10 @@ import org.springframework.util.Assert; * @author Dave Syer * @author Mahmoud Ben Hassine * @see CompletionPolicy + * + * @deprecated since 6.0 with no replacement. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public class StepExecutionSimpleCompletionPolicy implements StepExecutionListener, CompletionPolicy { private CompletionPolicy delegate; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PropertiesConverter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PropertiesConverter.java index 041026717..6e365e85c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PropertiesConverter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/PropertiesConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,10 @@ import org.springframework.util.StringUtils; * @author Lucas Ward * @author Dave Syer * @author Mahmoud Ben Hassine + * + * @deprecated since 6.0 with no replacement. Scheduled for removal in 6.2 or later. */ +@Deprecated(since = "6.0", forRemoval = true) public final class PropertiesConverter { private static final String LINE_SEPARATOR = "\n";