Updated readers and writers to set platform transaction
It is no longer provided by default by the job builder. https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#infrastructure-beans-configuration-with-enablebatchbatchprocessing
This commit is contained in:
@@ -35,6 +35,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -54,6 +55,9 @@ public class SingleStepJobAutoConfiguration {
|
||||
|
||||
private SingleStepJobProperties properties;
|
||||
|
||||
@Autowired
|
||||
PlatformTransactionManager transactionManager;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ItemProcessor<Map<String, Object>, Map<String, Object>> itemProcessor;
|
||||
|
||||
@@ -85,7 +89,7 @@ public class SingleStepJobAutoConfiguration {
|
||||
|
||||
stepBuilder.processor(this.itemProcessor);
|
||||
|
||||
Step step = stepBuilder.writer(itemWriter).build();
|
||||
Step step = stepBuilder.writer(itemWriter).transactionManager(this.transactionManager).build();
|
||||
|
||||
return this.jobBuilderFactory.get(this.properties.getJobName()).start(step).build();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.item.support.ListItemWriter;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
@@ -156,6 +158,11 @@ public class SingleStepJobAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class SimpleConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
List<Map<String, Object>> items = new ArrayList<>(3);
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.batch.item.file.separator.RecordSeparatorPolicy;
|
||||
import org.springframework.batch.item.file.transform.DefaultFieldSet;
|
||||
import org.springframework.batch.item.file.transform.LineTokenizer;
|
||||
import org.springframework.batch.item.support.ListItemWriter;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -45,6 +46,7 @@ import org.springframework.cloud.task.batch.autoconfigure.RangeConverter;
|
||||
import org.springframework.cloud.task.batch.autoconfigure.SingleStepJobAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -306,6 +308,11 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class CustomMappingConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemWriter<Map<String, Object>> itemWriter() {
|
||||
return new ListItemWriter<>();
|
||||
@@ -328,6 +335,11 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class JobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemWriter<Map<String, Object>> itemWriter() {
|
||||
return new ListItemWriter<>();
|
||||
@@ -339,6 +351,11 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class RecordSeparatorAndSkippedLinesJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RecordSeparatorPolicy recordSeparatorPolicy() {
|
||||
return new RecordSeparatorPolicy() {
|
||||
@@ -384,6 +401,11 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class CustomLineMapperConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LineMapper<Map<String, Object>> lineMapper() {
|
||||
return (line, lineNumber) -> {
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.batch.item.file.transform.FieldExtractor;
|
||||
import org.springframework.batch.item.file.transform.LineAggregator;
|
||||
import org.springframework.batch.item.file.transform.PassThroughLineAggregator;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
@@ -52,6 +53,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -362,6 +364,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class DelimitedJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
@@ -380,6 +387,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class LineAggregatorConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
@@ -403,6 +415,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class HeaderFooterConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
@@ -431,6 +448,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class FieldExtractorConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
@@ -459,6 +481,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class FormattedJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
@@ -477,6 +504,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class FormattedFieldExtractorJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FieldExtractor<Map<String, Object>> lineAggregator() {
|
||||
return item -> {
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.batch.item.database.ItemPreparedStatementSetter;
|
||||
import org.springframework.batch.item.database.ItemSqlParameterSourceProvider;
|
||||
import org.springframework.batch.item.database.JdbcBatchItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
@@ -58,6 +59,7 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@@ -263,6 +265,11 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class DelimitedJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
@@ -281,6 +288,11 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
public static class DelimitedDifferentKeyNameJobConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.database.JdbcCursorItemReader;
|
||||
import org.springframework.batch.item.support.ListItemWriter;
|
||||
import org.springframework.batch.item.util.ExecutionContextUserSupport;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -52,6 +53,7 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@@ -301,6 +303,11 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class TaskLauncherConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
private static Server defaultServer;
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProces
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.support.ListItemWriter;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -50,6 +51,7 @@ import org.springframework.kafka.support.serializer.JsonSerializer;
|
||||
import org.springframework.kafka.test.EmbeddedKafkaBroker;
|
||||
import org.springframework.kafka.test.context.EmbeddedKafka;
|
||||
import org.springframework.kafka.test.utils.KafkaTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -216,6 +218,11 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class CustomMappingConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemWriter<Map<String, Object>> itemWriter() {
|
||||
return new ListItemWriter<>();
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProces
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -47,6 +49,7 @@ import org.springframework.kafka.support.serializer.JsonDeserializer;
|
||||
import org.springframework.kafka.test.EmbeddedKafkaBroker;
|
||||
import org.springframework.kafka.test.context.EmbeddedKafka;
|
||||
import org.springframework.kafka.test.utils.KafkaTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -62,7 +65,7 @@ public class KafkaItemWriterTests {
|
||||
embeddedKafka.addTopics("topic2");
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void testBaseKafkaItemWriter() {
|
||||
final String topicName = "topic1";
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
@@ -119,6 +122,11 @@ public class KafkaItemWriterTests {
|
||||
@Configuration
|
||||
public static class CustomMappingConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemReader<Map<String, Object>> itemReader() {
|
||||
List<Map<String, Object>> list = new ArrayList<>(5);
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProces
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.support.ListItemWriter;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
@@ -53,6 +54,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.task.batch.autoconfigure.SingleStepJobAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -205,6 +207,11 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
@Configuration
|
||||
public static class BaseConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ListItemWriter<Map<String, Object>> itemWriter() {
|
||||
return new ListItemWriter<>();
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
@@ -58,6 +59,7 @@ import org.springframework.cloud.task.batch.autoconfigure.SingleStepJobAutoConfi
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -190,6 +192,11 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
|
||||
public static class ItemWriterConfiguration {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new ResourcelessTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RowMapper<Map<String, Object>> rowMapper() {
|
||||
return (rs, rowNum) -> {
|
||||
|
||||
Reference in New Issue
Block a user