I am trying to add message to the javax.validation
annotations in my Spring Boot app as shown below:
public static final String CANNOT_EMPTY = "%s field cannot be empty";
@Value
public class CreatePostRequest {
@NotBlank(message = String.format(CANNOT_EMPTY, title))
private String title;
// other fields
}
I am getting "Attribute value must be constant" error for the format()
method. So, how should I properly set messages for the javax.validation
annotations in my API requests? I do not want to add text to all of the fields and instead try to manage them in a Constant class and add the constant text variables to that annotations (for now, no need internationalization).
So, is there a better way? Any help would be appreciated.