自定义消息我添加了一个验证(@javax.validation.Valid
)我@RestController
并在@RequestBody
类我用@NotEmpty
注释:为SpringBoot REST风格的Bean验证工作不
public class Invoice {
@NotEmpty
private String commentText;
// omitted
}
当缺少commentText
REST调用,调用适当的错误返回到客户端:
{
"timestamp": 1475599494823,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.bind.MethodArgumentNotValidException",
"errors": [ {
"codes": [
"NotEmpty.invoice.commentText",
"NotEmpty.commentText",
"NotEmpty.java.lang.String",
"NotEmpty"
],
"arguments": [ {
"codes": [
"invoice.commentText",
"commentText"
],
"defaultMessage": "commentText",
"code": "commentText"
}],
"defaultMessage": "may not be empty",
"objectName": "invoice",
"field": "commentText",
"bindingFailure": false,
"code": "NotEmpty"
}],
"message": "Validation failed for object='invoice'. Error count: 1",
"path": "/api/invoices/1"
}
然后我创建的src /主/资源/ messages.properties与以下内容:
NotEmpty.invoice.commentText=Please type a comment
的问题是,代替自定义“请键入注释”原始的错误消息被返回给客户端。
我使用SpringBoot 1.4和YAML配置并在Eclipse中运行应用程序。
任何想法的问题可能是?
在这个问题上的任何更新? – user2049132