[Java] [Error Resolution] HV000030: No validator could be found for constraint ~ ~

less than 1 minute read

#####【environment】

  • ProductName: Mac OS X
  • ProductVersion: 10.14.6
  • BuildVersion: 18G2022
[Timing of encounter]
  • Developing application with spring-boot

Conclusion

  • I was using the wrong annotation.

Cause

Validation was set by a method that cannot be used in @Pattern.


#####【error contents】

There was an unexpected error (type=Internal Server Error, status=500).
HV000030: No validator could be found for constraint'javax.validation.constraints.Pattern' validating type'java.math.BigDecimal'. Check configuration for'price'

Translation:

HV000030: Constraint validating type'java.math.BigDecimal'
The validator for'javax.validation.constraints.Pattern' was not found. Check the composition of'price'.

Mistake


// Mandatory input, 1000 yen or more, convert to numerical value
@NotNull
@Min(1000)
@Pattern(regexp = "#,###") //Convert the specified pattern string to a number
private BigDecimal price;

Positive

// Mandatory input, 1000 yen or more, convert to numerical value
@NotNull
@Min(1000)
@NumberFormat(pattern = "#,###") //Converts the character string of the specified pattern to a number
private BigDecimal price;