Spring unit test issue with Validator

前端 未结 2 1965
無奈伤痛
無奈伤痛 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:11

    You need to have a default non argument public constructor. If you need to pass a Spring component into your validator, you may face a problem in test.

    I solved it by having a component which holds a service and has a static method to give the service.

提交回复
热议问题