In my Spring MVC application I'm making use of @Validated
objects in my controllers, using JSR-303. In my Spring application context I have defined a custom MessageSource, to read messages from a resources/messages.properties file.
I'm able to read and override javax.validation default messages (such as NotNull), but I get an error if I try to use message interpolation to read a parameter (e.g.: min or max from @Size(max=...)
.
Note that if I set a message directly in my model, it correctly shows the "interpolated" message (default message works fine too).
Model class:
public class Customer {
@JsonProperty("name")
@NotNull
@Size(max = 50) // if I add message = "This field must be less than {max} characters long" it works!
private String name;
// Other fields here + getters and setters
}
messages.properties:
Size=This field must be less than {max} characters long
NotNull=This field must be set.