I have spring boot project, a bean using javax validation API.
I'm trying to inject a service in my custom validator for a bean. But the service object is null.
I don't find a complete example that use Spring ConstraintValidator and i don't understand the configuration that some persons made for their integration tests in another topics.
I want to have a validator with constructor injection like this (i don't want to use @Autowired nore javax @Inject) :
@Component
public class CustomValidator implements ConstraintValidator<ValidCustomValidator, CustomObj> {
private ErreurService erreurService;
public CustomValidator(ErreurService erreurService) {
this.erreurService=erreurService;
}
@Override
public boolean isValid(CustomObj customObj, ConstraintValidatorContext context) {
erreurService.getMessages("");
return false;
}
}
** ErreurService**
@Service("ErreurService")
@Transactional
public class ErreurServiceImpl implements ErreurService {//...}
With this approach i got an Exception HV000064: Unable to instantiate ConstraintValidator
I try something with @Autowired but got always got a NPE. Can you help me please ?