What’s new in
Spring Batch 5?
Mahmoud Ben Hassine
Spring Batch Lead, VMware
@fmbenhassine
Slide 2
Slide 2 text
AGENDA
● New baseline
● New features
● Pruning
● Support policy
● What’s next?
Slide 3
Slide 3 text
AGENDA
● New baseline
● New features
● Pruning
● Support policy
● What’s next?
Slide 4
Slide 4 text
SPRING DEPENDENCIES
UPDATES
Slide 5
Slide 5 text
DEPENDENCIES UPDATES
● Spring Framework 6
● Spring Integration 6
● Spring Data 3
● Spring AMQP 3
● Spring for Apache Kafka 3
● Spring LDAP 3
● Spring Retry 2
● Micrometer 1.10
Slide 6
Slide 6 text
DEPENDENCIES UPDATES
● Spring Framework 6
● Spring Integration 6
● Spring Data 3
● Spring AMQP 3
● Spring for Apache Kafka 3
● Spring LDAP 3
● Spring Retry 2
● Micrometer 1.10
https://github.com/spring-projects/spring-framework/wiki
Slide 7
Slide 7 text
JAVA VERSION
UPDATES
Slide 8
Slide 8 text
JAVA VERSION UPDATES
● Java 17+
● Jakarta EE 9+
Slide 9
Slide 9 text
JAVA VERSION UPDATES
● Java 17+
● Jakarta EE 9+
https://www.youtube.com/watch?v=P7SI9mLwiqw
Slide 10
Slide 10 text
JAVA VERSION UPDATES
● Java 17+
● Jakarta EE 9+
https://www.youtube.com/watch?v=P7SI9mLwiqw
"You should expect to see these benefits without
having to change anything in your code, just by
updating to a newer Java version."
Aurelio García-Ribeyro - Senior Director of Product
Management - Java Platform Group
Slide 11
Slide 11 text
AGENDA
● New baseline
● New features
● Pruning
● Support policy
● What’s next?
Slide 12
Slide 12 text
JAVA RECORDS
SUPPORT UPDATES
Slide 13
Slide 13 text
JAVA RECORDS SUPPORT UPDATES
● Several improvements since 4.3
o Bug fixes
o Addition of RecordFieldExtractor for Java Records (similar to
BeanWrapperFieldExtractor for Java Beans)
● Usage of java.lang.Record APIs to improve configuration
o Automatic configuration of mappers in item readers based on item type
o Automatic configuration of extractors in item writers based on item type
Slide 14
Slide 14 text
JAVA RECORDS SUPPORT UPDATES
// given
class Person {int id; String name;}
// when
FlatFileItemReader reader = new FlatFileItemReaderBuilder()
.resource(new FileSystemResource("/data/persons.csv"))
.targetType(Person.class)
// set other properties
.build();
// then
// assertThat(reader.getFieldSetMapper()).isInstanceOf(BeanWrapperFieldSetMapper.class);
Slide 15
Slide 15 text
JAVA RECORDS SUPPORT UPDATES
// given
record Person (int id, String name) {}
// when
FlatFileItemReader reader = new FlatFileItemReaderBuilder()
.resource(new FileSystemResource("/data/persons.csv"))
.targetType(Person.class)
// set other properties
.build();
// then
// assertThat(reader.getFieldSetMapper()).isInstanceOf(RecordFieldSetMapper.class);
Slide 16
Slide 16 text
JAVA RECORDS SUPPORT UPDATES
public class FlatFileItemReaderBuilder {
private Class targetType;
public FlatFileItemReader build() {
FlatFileItemReader reader = new FlatFileItemReader();
if (this.targetType.isRecord()) {
reader.setFieldSetMapper(new RecordFieldSetMapper(this.targetType);
} else {
reader.setFieldSetMapper(new BeanWrapperFieldSetMapper(this.targetType);
}
}
}
Slide 17
Slide 17 text
BATCH CONFIGURATION
UPDATES
Slide 18
Slide 18 text
@EnableBatchProcessing IMPROVEMENTS
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder(“myJob”, jobRepository)
// define job flow as needed
.build();
}
}
Slide 19
Slide 19 text
@EnableBatchProcessing IMPROVEMENTS
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) { … }
@Bean
public BatchConfigurer batchConfigurer(DataSource dataSource) {
return new DefaultBatchConfigurer() {
@Override
public JobRepository getJobRepository() {
return new MyCustomJobRepository(dataSource);
}
};
}
}
Slide 20
Slide 20 text
@EnableBatchProcessing IMPROVEMENTS
@Configuration
@EnableBatchProcessing(dataSourceRef = "batchDataSource")
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) { … }
@Bean
public DataSource batchDataSource() {
return new MyDataSource();
}
}
Slide 21
Slide 21 text
@EnableBatchProcessing IMPROVEMENTS
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public BatchConfigurer batchConfigurer() {
return new DefaultBatchConfigurer() {
private Jackson2ExecutionContextStringSerializer customSerializer() {
Jackson2ExecutionContextStringSerializer serializer
= new Jackson2ExecutionContextStringSerializer();
// customize serializer
return serializer;
}
@Override
public JobRepository getJobRepository() {
JobRepositoryFactoryBean factoryBean
= new JobRepositoryFactoryBean();
factoryBean.setSerializer(customSerializer());
try {
return factoryBean.getObject();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
…
@Override
public JobExplorer getJobExplorer() {
JobExplorerFactoryBean factoryBean = new JobExplorerFactoryBean();
factoryBean.setSerializer(customSerializer());
// set other properties
try {
return factoryBean.getObject();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
Slide 22
Slide 22 text
@EnableBatchProcessing IMPROVEMENTS
@Configuration
@EnableBatchProcessing(executionContextSerializerRef = "myCustomSerializer")
public class MyJobConfiguration {
@Bean
public Jackson2ExecutionContextStringSerializer myCustomSerializer() {
Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
// customize serializer
return serializer;
}
}
Slide 23
Slide 23 text
ADDITION OF DefaultBatchConfiguration
@Configuration
public class MyJobConfiguration extends DefaultBatchConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder(“myJob”, jobRepository)
// define job flow as needed
.build();
}
}
Slide 24
Slide 24 text
ADDITION OF DefaultBatchConfiguration
@Configuration
public class MyJobConfiguration extends DefaultBatchConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder(“myJob”, jobRepository)
// define job flow as needed
.build();
}
@Override
public DataSource getDataSource() {
return new MyDataSource();
}
}
PARAMETER CONVERSION IMPROVEMENTS
Notation in v4: [+|-]parameterName(parameterType)=parameterValue
$>java -jar my-job.jar -schedule.date(date)=2023-01-26
Incompatible with
Spring Boot
Slide 28
Slide 28 text
PARAMETER CONVERSION IMPROVEMENTS
Notation in v4: [+|-]parameterName(parameterType)=parameterValue
$>java -jar my-job.jar -schedule.date(date)=2023-01-26
Incompatible with
Spring Boot
Incompatible with
Environment variables
Slide 29
Slide 29 text
PARAMETER CONVERSION IMPROVEMENTS
Notation in v4: [+|-]parameterName(parameterType)=parameterValue
$>java -jar my-job.jar -schedule.date(date)=2023-01-26
Incompatible with
Spring Boot
Incompatible with
Environment variables
Ambiguous
parameter type
PARAMETER TYPES IMPROVEMENTS
● Supported types in v4: String, Long, Double, Date
● Supported types in v5: Any type!
$>java -jar export-orders-job.jar customer=foo,my.domain.Customer
Slide 34
Slide 34 text
HOW TO SUPPORT CUSTOM PARAMETER TYPES?
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new MyJob(jobRepository);
}
}
Slide 35
Slide 35 text
HOW TO SUPPORT CUSTOM PARAMETER TYPES?
@Configuration
@EnableBatchProcessing(conversionServiceRef = "myCustomConversionService")
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new MyJob(jobRepository);
}
@Bean
public ConfigurableConversionService myCustomConversionService() {
DefaultConversionService conversionService = new DefaultConversionService();
// add converters from String to my.domain.Customer and vice-versa in conversionService
return conversionService;
}
}
Slide 36
Slide 36 text
BATCH META-DATA
UPDATES
Slide 37
Slide 37 text
NEW DATABASE SUPPORT
Slide 38
Slide 38 text
EXECUTION CONTEXT IMPROVEMENTS
● Serialization format updates
○ Base64 instead of JSON
○ Jackson is now optional
● Meta-data improvements
○ New “batch.version” attribute in the context
{
batch.stepType: “..”,
batch.restart: “..”,
..
batch.version: “5.0.0”
}
Slide 39
Slide 39 text
SCHEMA UPDATES
● Usage of sequences instead of tables for SQLServer
● Addition of column CREATE_TIME in BATCH_STEP_EXECUTION
● Addition of PARAMETER_NAME, PARAMETER_TYPE and
PARAMETER_VALUE in BATCH_JOB_EXECUTION_PARAMS
● Removal of BATCH_CONFIGURATION_LOCATION in
BATCH_JOB_EXECUTION
https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide
Slide 40
Slide 40 text
BATCH OBSERVABILITY
UPDATES
Slide 41
Slide 41 text
BATCH METRICS IMPROVEMENTS
● Several improvements since 4.3
○ Bug fixes
○ Consistent tag names
● Upgraded the usage of Observability APIs to Micrometer 1.10
● New metrics
○ Currently active step
○ Job launch count
Slide 42
Slide 42 text
HOW TO ENABLE BATCH METRICS?
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job() {
return new MyJob();
}
}
Slide 43
Slide 43 text
HOW TO ENABLE BATCH METRICS?
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job() {
return new MyJob();
}
@Bean
public ObservationRegistry observationRegistry() {
ObservationRegistry registry = ObservationRegistry.create();
// configure the registry as needed
return registry;
}
}
Slide 44
Slide 44 text
BATCH TRACING
Slide 45
Slide 45 text
HOW TO ENABLE BATCH TRACING?
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job() {
return new MyJob();
}
@Bean
public ObservationRegistry observationRegistry() {
ObservationRegistry registry = ObservationRegistry.create();
// configure the registry as needed
return registry;
}
}
Slide 46
Slide 46 text
HOW TO ENABLE BATCH TRACING?
@Configuration
@EnableBatchProcessing
public class MyJobConfiguration {
@Bean
public Job job() {
return new MyJob();
}
@Bean
public ObservationRegistry observationRegistry(Tracer tracer) {
ObservationRegistry registry = ObservationRegistry.create();
registry.observationConfig().observationHandler(
new DefaultTracingObservationHandler(tracer));
return registry;
}
}
Slide 47
Slide 47 text
GRAALVM SUPPORT
UPDATES
Slide 48
Slide 48 text
GRAALVM NATIVE SUPPORT IMPROVEMENTS
● Several improvements since v4.3
○ Bug fixes
○ Performance improvements
○ Tooling improvements
● Addition of native hints for AOT processing by Spring
○ Reflection hints
○ Resource hints
○ Proxy hints
○ Serialization hints
OTHER FEATURES
● New Maven Bill Of Materials
● UTF-8 by default in all areas of the framework
● Transaction support in JobExplorer and JobOperator
● Automatic registration of JobOperator with @EnableBatchProcessing
● SystemCommandTasklet improvements (new CommandRunner interface)
● Test utilities improvements + migration to Junit 5
● New documentation backend
Slide 54
Slide 54 text
AGENDA
● New baseline
● New features
● Pruning
● Support policy
● What’s next?
Slide 55
Slide 55 text
REMOVED FEATURES
● SQLFire support removal
● GemFire support removal
● JSR-352 implementation removal
● Deprecated APIs removal
https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#pruning
https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#removed-apis
Slide 56
Slide 56 text
AGENDA
● New baseline
● New features
● Pruning
● Support policy
● What’s next?
Slide 57
Slide 57 text
SUPPORT POLICY
● Same support policy as VMware Tanzu
● Same support period as Spring Boot
○ Spring Batch 5.0 (Spring Boot 3.0)
○ Spring Batch 4.3 (Spring Boot 2.7)
https://spring.io/projects/spring-batch#support
Slide 58
Slide 58 text
AGENDA
● New baseline
● New features
● Pruning
● Support policy
● What’s next?
Slide 59
Slide 59 text
WHAT’S NEXT?
● Support for 5.0.x and 4.3.x
● Spring Batch 5.1 (Spring Framework 6.1)
○ Better getting started experience
○ Virtual Threads (Project Loom) support
○ Revisit the chunk-oriented processing model implementation
Those are goals, not commitments!
Slide 60
Slide 60 text
60
Our vision
Empower Spring developers to continuously learn,
innovate and solve complex problems.
Core features
● Project-based courses with hands-on labs
● In-browser code editing and debugging
● Certification prep courses
● Spring Certified Professional certification
Sign up today
Get started for free at https://spring.academy.
For conference attendees
Use SPRINGIO-2023 at checkout by June 4th for a 20%
discount on a Spring Academy Pro subscription.
Slide 61
Slide 61 text
THANK YOU!
Q&A
Mahmoud Ben Hassine
Spring Batch Lead, VMware
@fmbenhassine
https://docs.spring.io/spring-batch/docs/5.0.0/reference/html/whatsnew.html
https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide