What’s new in Spring Batch 4.3

What’s New in Spring Batch 4.3

This release comes with a number of new features, performance improvements, dependency updates and API deprecations. This section describes the most important changes. For a complete list of changes, please refer to the release notes.spring-doc.cn

New features

New synchronized ItemStreamWriter

Similar to the SynchronizedItemStreamReader, this release introduces a SynchronizedItemStreamWriter. This feature is useful in multi-threaded steps where concurrent threads need to be synchronized to not override each other’s writes.spring-doc.cn

New JpaQueryProvider for named queries

This release introduces a new JpaNamedQueryProvider next to the JpaNativeQueryProvider to ease the configuration of JPA named queries when using the JpaPagingItemReader:spring-doc.cn

JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>()
   .name("fooReader")
   .queryProvider(new JpaNamedQueryProvider("allFoos", Foo.class))
   // set other properties on the reader
   .build();

New JpaCursorItemReader Implementation

JPA 2.2 added the ability to stream results as a cursor instead of only paging. This release introduces a new JPA item reader that uses this feature to stream results in a cursor-based fashion similar to the JdbcCursorItemReader and HibernateCursorItemReader.spring-doc.cn

New JobParametersIncrementer implementation

Similar to the RunIdIncrementer, this release adds a new JobParametersIncrementer that is based on a DataFieldMaxValueIncrementer from Spring Framework.spring-doc.cn

GraalVM Support

This release adds initial support to run Spring Batch applications on GraalVM. The support is still experimental and will be improved in future releases.spring-doc.cn

Java records Support

This release adds support to use Java records as items in chunk-oriented steps. The newly added RecordFieldSetMapper supports data mapping from flat files to Java records, as shown in the following example:spring-doc.cn

@Bean
public FlatFileItemReader<Person> itemReader() {
	return new FlatFileItemReaderBuilder<Person>()
			.name("personReader")
			.resource(new FileSystemResource("persons.csv"))
			.delimited()
			.names("id", "name")
			.fieldSetMapper(new RecordFieldSetMapper<>(Person.class))
			.build();
}

In this example, the Person type is a Java record defined as follows:spring-doc.cn

public record Person(int id, String name) { }

The FlatFileItemReader uses the new RecordFieldSetMapper to map data from the persons.csv file to records of type Person.spring-doc.cn

Performance improvements

Use bulk writes in RepositoryItemWriter

Up to version 4.2, in order to use CrudRepository#saveAll in RepositoryItemWriter, it was required to extend the writer and override write(List).spring-doc.cn

In this release, the RepositoryItemWriter has been updated to use CrudRepository#saveAll by default.spring-doc.cn

Use bulk writes in MongoItemWriter

The MongoItemWriter used MongoOperations#save() in a for loop to save items to the database. In this release, this writer has been updated to use org.springframework.data.mongodb.core.BulkOperations instead.spring-doc.cn

Job start/restart time improvement

The implementation of JobRepository#getStepExecutionCount() used to load all job executions and step executions in-memory to do the count on the framework side. In this release, the implementation has been changed to do a single call to the database with a SQL count query in order to count step executions.spring-doc.cn

Dependency updates

This release updates dependent Spring projects to the following versions:spring-doc.cn

Deprecations

API deprecation

The following is a list of APIs that have been deprecated in this release:spring-doc.cn

  • org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBeanspring-doc.cn

  • org.springframework.batch.core.explore.support.MapJobExplorerFactoryBeanspring-doc.cn

  • org.springframework.batch.core.repository.dao.MapJobInstanceDaospring-doc.cn

  • org.springframework.batch.core.repository.dao.MapJobExecutionDaospring-doc.cn

  • org.springframework.batch.core.repository.dao.MapStepExecutionDaospring-doc.cn

  • org.springframework.batch.core.repository.dao.MapExecutionContextDaospring-doc.cn

  • org.springframework.batch.item.data.AbstractNeo4jItemReaderspring-doc.cn

  • org.springframework.batch.item.file.transform.Alignmentspring-doc.cn

  • org.springframework.batch.item.xml.StaxUtilsspring-doc.cn

  • org.springframework.batch.core.launch.support.ScheduledJobParametersFactoryspring-doc.cn

  • org.springframework.batch.item.file.MultiResourceItemReader#getCurrentResource()spring-doc.cn

  • org.springframework.batch.core.JobExecution#stop()spring-doc.cn

Suggested replacements can be found in the Javadoc of each deprecated API.spring-doc.cn

SQLFire support deprecation

SQLFire has been in EOL since November 1st, 2014. This release deprecates the support of using SQLFire as a job repository and schedules it for removal in version 5.0.spring-doc.cn