一、如果是spring的话,好似在services里面@valid就可以自动验证了。但是在spring integration里面没有service概念,好似加在普通的transformer没有用,当整个类去jpa-outbound的时候会validate,但是如果是用sql update某些值而已,不会去validate,所以用下面办法去trigger。
1)dependency: hibernate-validator, validation-api
2)add tag in pojo, such as: @Pattern, @Email...
3)在spring 里加
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
4)在transformer里
@Autowired
Validator validator;
Pojo pojo=new Pojo();
ValidateFactory factory = Validation.buildDefaultValidationFactory();
this.validator = factory.getValidator();
Set<ConstraintViolation<Pojo>> constraintViolations = this.validator.validate(pojo);
//below have the violation info
System.out.println(constraintViolations.toString());