Sunday, 11 April 2021

Bean Validation: customize Error Messages

Bean validation annotations provide default error messages.

 

For example, following snippet specify, property ‘name’ must have minium 5 characters.

 

@Size(min=5)

private String name;

 

In case of name with below 5 characters in length, you will get following default message.

 

name,size must be between 5 and 2147483647

 

There are two ways to add custom messages.

a.   Using the ‘message’ attribute of the constraint.

b.   Globally configure validation error messages in a property file

Previous                                                    Next                                                    Home

No comments:

Post a Comment