Spring Batch Bean 校验 API 支持
这个发布版本带来了一个新的 ValidatingItemProcessor 实现,这个实现被称为
https://www.cwiki.us/display/SpringBatchZH/Bean+Validation+API+support
BeanValidatingItemProcessor
。能够让你使用 Bean Validation API (JSR-303)
来校验 Item 的注解。例如给定下面的类型 Person:
class Person { @NotEmpty private String name; public Person(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }你可以通过在你的应用上下文中声明一个
BeanValidatingItemProcessor
并在你的原始块步骤中注册来校验 items:@Bean public BeanValidatingItemProcessor<Person> beanValidatingItemProcessor() throws Exception { BeanValidatingItemProcessor<Person> beanValidatingItemProcessor = new BeanValidatingItemProcessor<>(); beanValidatingItemProcessor.setFilter(true); return beanValidatingItemProcessor; }
https://www.cwiki.us/display/SpringBatchZH/Bean+Validation+API+support
Comments
Post a Comment