0

I was writing pact provider test which validate the incoming request from consumer and i have used custom constraint validator for that like

public class MaxRecipients implements
    ConstraintValidator<MaxRecipientsSize, Collection> {

  @Value("${recipient.max.size}")
  private Integer recipientMaxSize;


  @Override
  public void initialize(MaxRecipientsSize constraintAnnotation) {
  }

  @Override
  public boolean isValid(Collection value, ConstraintValidatorContext cvc) {
    if (isEmpty(value)) {
      return TRUE;
    }

Here when control comes, the value of recipientMaxSize becomes null, i have configured the property in application properties and property source. Can someone help on this?

Usf Shilpa
  • 11
  • 2

1 Answers1

0

I think your class MaxRecipients lacks the annotation @Component or similar. Because of that, @Value is not filled through Spring.

Milgo
  • 2,617
  • 4
  • 22
  • 37
  • i have used @component also – Usf Shilpa Sep 07 '20 at 14:45
  • Then your applications.properties / application.yml is not loaded properly. Please add your complete code (including @Component) and your application.properties/yml – Milgo Sep 07 '20 at 15:13
  • https://stackoverflow.com/questions/13350537/inject-service-in-constraintvalidator-bean-validator-jsr-303-spring has an answer. – gungor Sep 07 '20 at 20:51