How to autowire service in ConstraintValidator

前端 未结 3 1858

I\'m writting my application using Spring MVC. I want to validate is e-mail exists in database when user is registering. I\'ve written my own annotation constraint named

3条回答
  •  [愿得一人]
    2021-01-19 16:45

    Don't you have a Validator configured in your bean context. If you are bootstrapping Validator via Validation.buildDefaultValidatorFactory(); you are bypassing the Spring mechanism and you get a Validator which is not aware of Spring beans and components. Hence injection is not working. In your test you want to get hold of the Spring provided Validator.

提交回复
热议问题