In the process of implementing kv-storage, there was a task to limit the use of characters in the transmitted key. I wrote my own validator inheriting from org.springframework.validation.Validator , declared it as @Component , but the magic did not happen and it was not invoked. The actual configuration of Spring itself, as far as I understand, uses the Hibernate Validator "under the hood". WHERE and how can I add an arbitrary validator to existing ones?
|
1 answer
On the Internet, everywhere there is a version with InitBinder and manual validation, which, as it turned out, works perfectly in automatic mode:
@RestController class MyController { @InitBinder public void initBinder(WebDataBinder binder) { binder.addValidators(new MyCustomValidator()); } ... } |