Search code examples
javaspringhibernate-validator

@NotEmpty not displaying customised exception message


I used @NotEmpty (hibernate validator) annotation on a variable. created messages.properties file where I put proper entry using "AnnotationName.objectName.variable=string_to_be_displayed". Still I get default error message "may not be null". In spring config servlet, also I binded messages.properties. But no success. please help. I tried many times.

attaching screenshot of logenter image description here

Response body is : enter image description here


Solution

  • At last I found the solution of my problem.

    To display customised messages, follow this :

    @NotBlank(message = "your messages")
    private String variableName;
    

    You can use (messege="...") with every hibernate validator defined annotations, eg. @Range, @Size, @NotEmpty, etc.

    No need to create any ValidationMessages.properties file or messages.properties file for your own. No need to do anything in spring-context.xml file for binding.

    You may follow this link for more knowledge on this issue. Enjoy coding with your own messages !