diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java index cb3829796..a8341b553 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java @@ -24,7 +24,11 @@ import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.repository.JobRepository; import org.springframework.context.annotation.Import; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** *
@@ -36,7 +40,6 @@ import java.lang.annotation.*; *
* @Configuration
* @EnableBatchProcessing
- * @Import(DataSourceConfiguration.class)
* public class AppConfig {
*
* @Bean
@@ -72,18 +75,18 @@ import java.lang.annotation.*;
*
* modular=true, the context also
* contains an {@link AutomaticJobRegistrar}. The job registrar is useful for modularizing
* your configuration if there are multiple jobs. It works by creating separate child
@@ -141,7 +144,8 @@ import java.lang.annotation.*;
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @author Taeik Lim
- *
+ * @see EnableJdbcJobRepository
+ * @see EnableMongoJobRepository
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableJdbcJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableJdbcJobRepository.java
index a9c912699..ba1e9d9f0 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableJdbcJobRepository.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableJdbcJobRepository.java
@@ -17,6 +17,8 @@ package org.springframework.batch.core.configuration.annotation;
import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
import org.springframework.batch.support.DatabaseType;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.Isolation;
@@ -27,6 +29,23 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.sql.Types;
+import javax.sql.DataSource;
+
+/**
+ * Annotation to enable a JDBC-based infrastructure in a Spring Batch application.
+ * + * This annotation should be used on a {@link Configuration @Configuration} class + * annotated with {@link EnableBatchProcessing }. It will automatically configure the + * necessary beans for a JDBC-based infrastructure, including a job repository. + *
+ * The default configuration assumes that a {@link DataSource} bean named "dataSource" and + * a {@link DataSourceTransactionManager} bean named "transactionManager" are available in + * the application context. + * + * @author Mahmoud Ben Hassine + * @since 6.0 + * @see EnableBatchProcessing + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @@ -62,13 +81,15 @@ public @interface EnableJdbcJobRepository { String charset() default "UTF-8"; /** - * The Batch tables prefix. Defaults to {@literal "BATCH_"}. + * The Batch tables prefix. Defaults to + * {@link AbstractJdbcBatchMetadataDao#DEFAULT_TABLE_PREFIX}. * @return the Batch table prefix */ String tablePrefix() default AbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX; /** - * The maximum length of exit messages in the database. + * The maximum length of exit messages in the database. Defaults to + * {@link AbstractJdbcBatchMetadataDao#DEFAULT_EXIT_MESSAGE_LENGTH} * @return the maximum length of exit messages in the database */ int maxVarCharLength() default AbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH; @@ -92,6 +113,11 @@ public @interface EnableJdbcJobRepository { */ String transactionManagerRef() default "transactionManager"; + /** + * Set the {@link JdbcOperations} to use in the job repository. + * @return the bean name of the {@link JdbcOperations} to use. Defaults to + * {@literal jdbcTemplate}. + */ String jdbcOperationsRef() default "jdbcTemplate"; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableMongoJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableMongoJobRepository.java index 626933b9a..f4233eb1a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableMongoJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableMongoJobRepository.java @@ -15,7 +15,9 @@ */ package org.springframework.batch.core.configuration.annotation; +import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.MongoTransactionManager; +import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.transaction.annotation.Isolation; import java.lang.annotation.Documented; @@ -24,6 +26,21 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * * Annotation to enable a MongoDB-based job repository in a Spring Batch application. + *
+ * This annotation should be used on a {@link Configuration @Configuration} class + * annotated with {@link EnableBatchProcessing}. It will automatically configure the + * necessary beans for a MongoDB-based infrastructure, including a job repository. + *
+ * The default configuration assumes that a {@link MongoOperations} bean named + * "mongoTemplate" and a {@link MongoTransactionManager} bean named "transactionManager" + * are available in the application context. + * + * @author Mahmoud Ben Hassine + * @since 6.0 + * @see EnableBatchProcessing + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java index 81faf33ee..813c954b7 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java @@ -49,7 +49,7 @@ import org.springframework.transaction.annotation.Isolation; *