简体   繁体   中英

Facing issue with Spring mvc/boot custom validator, it not showing the error message properly

We're developing a web application using Spring MVC/Boot, and we've created custom constraint/validators for both fields and classes. Both work, but the error message isn't displayed correctly; in the case of a class level validator, it shows Constraint.bean as an error message, and in the case of a field level validator, it shows Constraint.bean.field as an error message. I supply hard coded error messages in the Constraint as the default message and in the bean field where we apply the validator annotation, as well as at the class level validatior annotation in the bean class, but the default error message or overlapped error message does not appear. The custom annotation is Constraint, and the class where we added validation is bean.

It show error messages like

  1. In case of field validator ContactNumberConstraint.EmployeeBean.phone
  2. In case of class level validator ContactNumberConstraint.EmployeeBean

Is there any property we need to set in application.properties file or any other setting we missed, please help to resolve issue.

That's the message key which is supplied inside message() method. the messages should be configured in resources as message bundle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM