diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfiguration.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfiguration.java index 4bb5d7e8..8193c03c 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfiguration.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfiguration.java @@ -78,7 +78,7 @@ public class SingleStepJobAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnProperty(prefix = "spring.batch.job", name = "jobName") + @ConditionalOnProperty(prefix = "spring.batch.job", name = "job-name") public Job job(ItemReader> itemReader, ItemWriter> itemWriter) { @@ -95,5 +95,4 @@ public class SingleStepJobAutoConfiguration { return this.jobBuilderFactory.get(this.properties.getJobName()).start(step) .build(); } - } diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobProperties.java index a8021c34..3a0d7c8e 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobProperties.java @@ -27,10 +27,19 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job") public class SingleStepJobProperties { + /** + * Name of the step in the single step job. + */ private String stepName; + /** + * The number of items to process per transaction or chunk. + */ private Integer chunkSize; + /** + * The name of the job. + */ private String jobName; /** diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemReaderProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemReaderProperties.java index c43dab14..badfdb9e 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemReaderProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemReaderProperties.java @@ -34,38 +34,95 @@ import org.springframework.core.io.Resource; @ConfigurationProperties(prefix = "spring.batch.job.flatfileitemreader") public class FlatFileItemReaderProperties { + /** + * Determines whether the state of the reader is persisted. Default is {@code true}. + */ private boolean saveState = true; + /** + * The name used to calculate the key within the + * {@link org.springframework.batch.item.ExecutionContext}. Required if + * {@link #setSaveState} is set to {@code true}. + */ private String name; + /** + * Configure the maximum number of items to be read. + */ private int maxItemCount = Integer.MAX_VALUE; + /** + * Index for the current item. Also used on restarts to indicate where to start from. + */ private int currentItemCount = 0; + /** + * A list of {@code String} elements used to indicate which records are comments. + */ private List comments = new ArrayList<>(); + /** + * The {@link Resource} to be used as input. + */ private Resource resource; + /** + * Configure whether the reader should be in strict mode (require the input + * {@link Resource} to exist). + */ private boolean strict = true; + /** + * Configure the encoding used by the reader to read the input source. The default value + * is {@link FlatFileItemReader#DEFAULT_CHARSET}. + */ private String encoding = FlatFileItemReader.DEFAULT_CHARSET; + /** + * The number of lines to skip at the beginning of reading the file. + */ private int linesToSkip = 0; + /** + * Indicates that a {@link DelimitedLineTokenizer} should be used to parse each line. + */ private boolean delimited = false; + /** + * Define the delimiter for the file. + */ private String delimiter = DelimitedLineTokenizer.DELIMITER_COMMA; + /** + * Define the character used to quote fields. + */ private char quoteCharacter = DelimitedLineTokenizer.DEFAULT_QUOTE_CHARACTER; + /** + * A list of indices of the fields within a delimited file to be included. + */ private List includedFields = new ArrayList<>(); + /** + * Indicates that a + * {@link org.springframework.batch.item.file.transform.FixedLengthTokenizer} should + * be used to parse the records in the file. + */ private boolean fixedLength = false; + /** + * The column ranges to be used to parse a fixed width file. + */ private List ranges = new ArrayList<>(); + /** + * The names of the fields to be parsed from the file. + */ private String[] names; + /** + * Indicates whether the number of tokens must match the number of configured fields. + */ private boolean parsingStrict = true; /** diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterProperties.java index 1776f38c..39f7191f 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterProperties.java @@ -31,40 +31,99 @@ import org.springframework.core.io.Resource; @ConfigurationProperties(prefix = "spring.batch.job.flatfileitemwriter") public class FlatFileItemWriterProperties { + /** + * The {@link Resource} to be used as output. + */ private Resource resource; + /** + * Configure the use of the {@code DelimitedLineAggregator} to generate the output per item. + * Default is {@code false}. + */ private boolean delimited; + /** + * Indicates to use a {@code FormatterLineAggregator} to generate the output per item. + * Default is {@code false}. + */ private boolean formatted; + /** + * Configure the format the {@code FormatterLineAggregator} uses for each item. + */ private String format; + /** + * Configure the {@code Locale} to use when generating the output. + */ private Locale locale = Locale.getDefault(); + /** + * Configure the maximum record length. If 0, the size is unbounded. + */ private int maximumLength = 0; + /** + * Configure the minimum record length. + */ private int minimumLength = 0; + /** + * Configure the {@code String} used to delimit the fields in the output file. + */ private String delimiter = ","; + /** + * File encoding for the output file. Defaults to {@code FlatFileItemWriter.DEFAULT_CHARSET}) + */ private String encoding = FlatFileItemWriter.DEFAULT_CHARSET; + /** + * A flag indicating that changes should be force-synced to disk on flush. Defaults to {@code false}. + */ private boolean forceSync = false; + /** + * Names of the fields to be extracted into the output. + */ private String[] names; + /** + * Configure if the output file is found if it should be appended to. Defaults to {@code false}. + */ private boolean append = false; + /** + * String used to separate lines in output. Defaults to the {@code System} property {@code line.separator}. + */ private String lineSeparator = FlatFileItemWriter.DEFAULT_LINE_SEPARATOR; + /** + * The name used to calculate the key within the + * {@link org.springframework.batch.item.ExecutionContext}. Required if + * {@link #setSaveState} is set to {@code true}. + */ private String name; + /** + * Returns the configured value of whether the state of the reader is persisted. + */ private boolean saveState = true; + /** + * Indicates whether the output file should be deleted if no output was written to it. + * Defaults to {@code false}. + */ private boolean shouldDeleteIfEmpty = false; + /** + * Indicates whether an existing output file should be deleted on startup. Defaults to {@code true}. + */ private boolean shouldDeleteIfExists = true; + /** + * Indicates whether flushing the buffer should be delayed while a transaction is active. Defaults to {@code true}. + */ private boolean transactional = FlatFileItemWriter.DEFAULT_TRANSACTIONAL; /** diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcBatchItemWriterProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcBatchItemWriterProperties.java index 3b36dfcc..c213a0c7 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcBatchItemWriterProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcBatchItemWriterProperties.java @@ -27,10 +27,21 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job.jdbcbatchitemwriter") public class JdbcBatchItemWriterProperties { + /** + * The name used to calculate the key within the + * {@link org.springframework.batch.item.ExecutionContext}. + */ private String name; + /** + * The SQL statement to be used to update the database. + */ private String sql; + /** + * If set to {@code true}, confirms that every insert results in the update of at least one + * row in the database. Defaults to {@code true}. + */ private boolean assertUpdates = true; /** diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcCursorItemReaderProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcCursorItemReaderProperties.java index d447783b..41c67319 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcCursorItemReaderProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/jdbc/JdbcCursorItemReaderProperties.java @@ -25,28 +25,72 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job.jdbccursoritemreader") public class JdbcCursorItemReaderProperties { + /** + * Configure whether the state of the + * {@link org.springframework.batch.item.ItemStreamSupport} should be persisted + * within the {@link org.springframework.batch.item.ExecutionContext} for + * restart purposes. Defaults to {@code true}. + */ private boolean saveState = true; + /** + * Returns the configured value of the name used to calculate {@code ExecutionContext} keys. + */ private String name; + /** + * Configure the maximum number of items to be read. + */ private int maxItemCount = Integer.MAX_VALUE; + /** + * Index for the current item. Also used on restarts to indicate where to start from. + * Defaults to 0. + */ private int currentItemCount = 0; + /** + * The number of items to return each time the cursor fetches from the server. + */ private int fetchSize; + /** + * Sets the maximum number of rows to be read with this reader. + */ private int maxRows; + /** + * The time in milliseconds for the query to timeout. + */ private int queryTimeout; + /** + * Establishes whether SQL warnings should be ignored. Defaults to {@code false}. + */ private boolean ignoreWarnings; + /** + * Sets whether the cursor's position should be validated with each item read. + * Defaults to {@code false}. + */ private boolean verifyCursorPosition; + /** + * Establishes {@code false} the driver supports absolute positioning of a cursor. + * Defaults to {@code false}. + */ private boolean driverSupportsAbsolute; + /** + * Establishes whether the connection used for the cursor is being used by all other + * processing and is, therefore, part of the same transaction. + * Defaults to {@code false} + */ private boolean useSharedExtendedConnection; + /** + * The SQL query to be executed. + */ private String sql; /** @@ -226,8 +270,8 @@ public class JdbcCursorItemReaderProperties { } /** - * Provides if the the connection used for the cursor is being used by all other - * processing, therefor part of the same transaction. + * Sets whether the connection used for the cursor is being used by all other + * processing and is, therefore, part of the same transaction. * @return true if the connection is shared beyond this query */ public boolean isUseSharedExtendedConnection() { @@ -235,8 +279,8 @@ public class JdbcCursorItemReaderProperties { } /** - * Sets if the the connection used for the cursor is being used by all other - * processing, therefor part of the same transaction. + * Sets whether the the connection used for the cursor is being used by all other + * processing and is, therefore, part of the same transaction. * @param useSharedExtendedConnection true if the connection is shared beyond this * query * @see org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder#useSharedExtendedConnection(boolean) diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemReaderProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemReaderProperties.java index 1f08150c..44ea9ca8 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemReaderProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemReaderProperties.java @@ -30,14 +30,33 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job.kafkaitemreader") public class KafkaItemReaderProperties { + /** + * The name used to calculate the key within the + * {@link org.springframework.batch.item.ExecutionContext}. + */ private String name; + /** + * The topic name from which the messages is read. + */ private String topic; + /** + * A list of partitions to manually assign to the consumer. Defaults to a single entry + * value of 1. + */ private List partitions = new ArrayList<>(); + /** + * Establish the {@code pollTimeout} for the {@code poll()} operations. Defaults to 30 seconds. + */ private long pollTimeOutInSeconds = 30L; + /** + * Configure whether the state of the {@link org.springframework.batch.item.ItemStreamSupport} + * should be persisted within the {@link org.springframework.batch.item.ExecutionContext} + * for restart purposes. Defaults to {@code true}. + */ private boolean saveState = true; /** diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemWriterProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemWriterProperties.java index 9b75be30..617eb477 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemWriterProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/kafka/KafkaItemWriterProperties.java @@ -27,8 +27,15 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job.kafkaitemwriter") public class KafkaItemWriterProperties { + /** + * The topic name from which the messages are written. + */ private String topic; + /** + * Indicate whether the items being passed to the writer are all to be sent as delete + * events to the topic. Defaults to {@code false}. + */ private boolean delete; /** @@ -40,7 +47,7 @@ public class KafkaItemWriterProperties { } /** - * The topic name from which the messages will be read. + * The topic name from which the messages are written. * @param topic name of the topic */ public void setTopic(String topic) { diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemReaderProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemReaderProperties.java index 64e24e61..ba3e8ee8 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemReaderProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemReaderProperties.java @@ -28,8 +28,15 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job.amqpitemreader") public class AmqpItemReaderProperties { + /** + * Enables or disables the {@code AmqpItemReader}. Defaults to {@code false}. + */ private boolean enabled; + /** + * Establishes whether the {@link Jackson2JsonMessageConverter} is to be used as a + * message converter. Defaults to {@code true}. + */ private boolean jsonConverterEnabled = true; /** diff --git a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemWriterProperties.java b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemWriterProperties.java index 6e90fbb8..418c681c 100644 --- a/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemWriterProperties.java +++ b/spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/rabbit/AmqpItemWriterProperties.java @@ -26,21 +26,28 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.batch.job.amqpitemwriter") public class AmqpItemWriterProperties { + /** + * Enables or disables the AmqpItemWriter. Defaults to {@code false}. + */ private boolean enabled; + /** + * Establishes whether the {@link Jackson2JsonMessageConverter} is to be used as a + * message converter. Defaults to {@code true}. + */ private boolean jsonConverterEnabled = true; /** * The state of the enabled flag. - * @return true if AmqpItemWriter is enabled. Otherwise false. + * @return {@code true} if {@code AmqpItemWriter} is enabled. Otherwise {@code false}. */ public boolean isEnabled() { return enabled; } /** - * Enables or disables the AmqpItemReader. - * @param enabled if true then AmqpItemWriter will be enabled. Defaults to false. + * Enables or disables the {@code AmqpItemWriter}. + * @param enabled if {@code true} then {@code AmqpItemWriter} is enabled. Defaults to {@code false}. */ public void setEnabled(boolean enabled) { this.enabled = enabled; diff --git a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java index cf5277be..16a5fa99 100644 --- a/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java +++ b/spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfigurationTests.java @@ -112,6 +112,25 @@ public class SingleStepJobAutoConfigurationTests { "spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5"); + validateConfiguration(applicationContextRunner); + } + + @Test + public void testSimpleConfigurationKabobStyle() { + ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner() + .withUserConfiguration(SimpleConfiguration.class) + .withConfiguration( + AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, + BatchAutoConfiguration.class, + SingleStepJobAutoConfiguration.class)) + .withPropertyValues("spring.batch.job.job-name=job", + "spring.batch.job.step-name=step1", + "spring.batch.job.chunk-size=5"); + + validateConfiguration(applicationContextRunner); + } + + private void validateConfiguration(ApplicationContextRunner applicationContextRunner) { applicationContextRunner.run((context) -> { JobLauncher jobLauncher = context.getBean(JobLauncher.class); diff --git a/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java b/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java index 1716a880..4dc1f3e7 100644 --- a/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java +++ b/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java @@ -78,7 +78,7 @@ public class TaskSinkApplicationTests { assertThat(actualRequest.getDefinition().getProperties() .get("server.port")).isEqualTo("0"); assertThat(actualRequest.getResource().toString() - .contains("maven://org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE")) + .contains("org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE")) .isTrue(); } }