grails - 使用 grails 3.3 在命令对象中使用共享约束
问题描述
我在将旧单元测试从 grails 2.5.4 迁移到 grails 3.3 时遇到问题
我有很多使用共享首选项的命令。一个例子,de UserController里面的UserCommand:
class UserCommand implements Validateable {
String firstName
static constraints = {
firstName shared: 'nonNullableString'
}
}
在 application.groovy 我以这种方式定义了约束:
grails.gorm.default.constraints = {
nonNullableString(blank: false, maxSize: 255)
}
我也将User
域定义为:
class User {
String firstName
static constraints = {
firstName shared: 'nonNullableString'
}
}
写一个我做的测试:
User user = new User()
user.validate()
它按预期工作。但是当我这样做时:
UserCommand command = new UserCommand()
command.validate()
它抛出一个异常。
`grails.gorm.validation.exceptions.ValidationConfigurationException: Property [User.firstName] references shared constraint [nonNullableString:null], which doesn't exist!`
我以为我在 application.groovy 文件中犯了一个错误,但共享约束适用于域..
这是一个具有相同问题的示例项目:https ://github.com/almejo/commandtest
有什么想法吗?
解决方案
推荐阅读
- java - 如何从 JSON 对象中获取所有键作为 Java 中的字符串数组
- amazon-ecs - 如何访问 AWS ECS 容器?
- yii2 - 将数据直接传递给 yii2-tree-manager
- javascript - 尽管 JavaScript 中的条件为真,但不显示值
- python - 烧瓶内部蓝图找不到模板
- python - 将交叉表另存为 PDF - Python
- bash - Bash 检测 WSL
- reactjs - 使用 Nextjs 的 getInitialProps 为 firebase DB 设置状态
- elasticsearch - ElasticSearch 应该查询
- java - 如何在hibernate中使用类org.hibernate.annotations.Table的@Table注解