{{announcement.body}}
{{announcement.title}}

Spring Batch - ItemValidations

DZone 's Guide to

Spring Batch - ItemValidations

In this tutorial, we'll learn how to implement the Custom Item Validations to validate the items you want to validate in Spring with MySQL.

· Database Zone ·
Free Resource

In this tutorial, we'll learn how to implement the Custom Item Validations to validate the items you want to validate. The Spring Batch V4.1 release has bring below features.

1.4. Bean Validation API support

This release brings a new ValidatingItemProcessor implementation called BeanValidatingItemProcessor which allows you to validate items annotated with the Bean Validation API (JSR-303) annotations 

1.5. JSR-305 support

This release adds support for JSR-305 annotations. It leverages Spring Framework’s Null-safety annotations and adds them on all public APIs of Spring Batch.

These annotations will not only enforce null-safety when using Spring Batch APIs, but also can be used by IDEs to provide useful information related to nullability. For example, if a user wants to implement the ItemReader interface, any IDE supporting JSR-305 annotations will generate something like:

Java


The @Nullable annotation present on the read method makes it clear that the contract of this method says it may return null. This enforces what is said in its Javadoc, that the read method should return null when the data source is exhausted.


Model

Java
 


CustomLineAggregator.java

Java
 


JobConfiguration.java

Java
 


CustomerRowMapper.java

Java
 


CustomerValidator.java

Java
 


ItemValidationApplication.java

Java
 


application.properties

Properties files
 


schema.sql

SQL


If you run this code and you'll items having first name starts with the "A" gets filtered out.

Topics:
jdbc, mysql, spring, spring batch, tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}