- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Spring Boot 构建 Web API。端点之一采用 JSON 发布请求。我想在某些字段上设置验证消息。所以我在/src/main/resources 下添加了一个 ValidationMessages.properties
以及 application.properties
。该文件中添加了以下行:
doorid.notnull=Door ID is required
doorid.notblank=Door ID is empty
在我的 JSON 实体类中,我有这样注释的字段“doorId”:
@NotNull(message = "{doorid.notnull}")
@NotBlank (message = "{doorid.notblank}")
private String doorId;
当我使用 doorId 作为空字符串测试 API 时,它只是返回代码 406,没有任何消息。在服务器日志中,它说:
ValidationMessages found.
ContributorValidationMessages not found.
ContributorValidationMessages
到底是什么?为什么除了 ValidationMessages
之外我还需要它?
编辑:
添加一个ContributorValidationMessages.properties
在与ValidationMessages.properties
同路径同行后,好像什么都找到了。
ValidationMessages found.
ContributorValidationMessages found.
org.hibernate.validator.ValidationMessages found.
但是,当我用空的 doorId
尝试相同的请求时,它只返回 406。验证消息没有在任何地方显示。
最佳答案
ContributorValidationMessages
是一个属性文件,用于放置自定义约束的默认消息。
根据相关blog post :
The bundle ContributorValidationMessages is queried by Hibernate Validator if the standard ValidationMessages bundle doesn’t contain a given message key, allowing library authors to provide default messages for their constraints as part of their JAR.
并根据相关document :
This mechanism is also helpful when creating large multi-module applications: Instead of putting all the constraint messages into one single bundle, you can have one resource bundle per module containing only those messages of that module.
关于json - Spring 启动 : ValidationMessages found but ContributorValidationMessages not found?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48255380/
我正在使用 Spring Boot 构建 Web API。端点之一采用 JSON 发布请求。我想在某些字段上设置验证消息。所以我在/src/main/resources 下添加了一个 Validati
我是一名优秀的程序员,十分优秀!