"The Hibernate Validator - JSR 303 Reference Implementation - Reference Guide" says something about portality:
Attention
Any restriction implementation based on ConstraintValidatorFactory implementation-specific behavior (dependency injection, no no-arg constructor, etc.) is not considered portable.
So is that bad? In my opinion, this is not so. Of course, now you are connected to the DI container (Spring) and cannot easily reuse validators (for example, when not using Spring). On the other hand, with your Spring factory validators, you can take full advantage of the framework and do very hard work (read revision data for entities and compare previous states, call arbitrary services, improve or localize message checking, ... )
One thing that you must be very careful about is that the semantics of the validator are usually read-only and should not cause side effects by causing them. For example, it is not by accident that you delete data in the database due to some automatic cleaning by calling a (transactional) service or reading the data inside your validator.
jeha
source share