Spring unit test issue with Validator

前端 未结 2 2021
無奈伤痛
無奈伤痛 2021-01-22 11:19

I am trying to write unit test for a validator class that I have. So within my UniqueEmailValidator class, I injected a @Service component to check if it exist.

         


        
2条回答
  •  天命终不由人
    2021-01-22 12:09

    The actual problem is deep down in the stack-trace that you've provided:

    Caused by: java.lang.NoSuchMethodException: com.x.x.validator.UniqueEmailValidator.()
    at java.lang.Class.getConstructor0(Unknown Source)
    ... 52 more
    

    This error message is thrown because there is some code that is trying to instantiate the UniqueEmailValidator class constructor without any parameters. The problem will be resolved by adding a default constructor to this class:

    public class UniqueEmailValidator implements ConstraintValidator {
        public UniqueEmailValidator() {
        }
        ...
    }
    

    Hope this helps!

提交回复
热议问题