0

尝试从使用共享约束的域类导入约束时,我得到以下异常。绑定阶段出现异常

例外:

Property [somePackage.User.email] references shared constraint [email:null], which doesn't exist!

领域:

class User {
    String email
    static constraints = {
        email(shared: 'email', unique: true)
}

命令

class UpdateClientCommand {
    String email

    static constraints = {
        importFrom User
    }

}

堆栈跟踪:

Property [clearhub.User.email] references shared constraint [email:null], which doesn't exist!. Stacktrace follows:


 Caused by: org.grails.core.exceptions.GrailsConfigurationException: Property [mypackage.User.email] references shared constraint [email:null], which doesn't exist!
        at org.grails.validation.DefaultConstraintEvaluator.applySharedConstraints(DefaultConstraintEvaluator.java:287)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraintsMap(DefaultConstraintEvaluator.java:245)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:132)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:119)
        at org.grails.validation.DefaultConstraintEvaluator.evaluate(DefaultConstraintEvaluator.java:80)
        at org.grails.validation.ConstrainedPropertyBuilder.handleImportFrom(ConstrainedPropertyBuilder.java:173)
        at org.grails.validation.ConstrainedPropertyBuilder.createNode(ConstrainedPropertyBuilder.java:165)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:101)
        at org.grails.validation.ConstrainedPropertyBuilder.doInvokeMethod(ConstrainedPropertyBuilder.java:72)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:67)
        at mypackage.UpdateClientCommand$__clinit__closure1.doCall(ClientController.groovy:47)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraintsMap(DefaultConstraintEvaluator.java:240)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:144)
        at org.grails.validation.DefaultConstraintEvaluator.evaluate(DefaultConstraintEvaluator.java:92)
        at grails.validation.Validateable$Trait$Helper.validate(Validateable.groovy:149)
        at grails.validation.Validateable$Trait$Helper.validate(Validateable.groovy:82)
        ... 37 common frames omitted

有任何想法吗 ?

4

1 回答 1

0

如果您将约束定义为共享- 它应该在grails-app/conf/Config.groovy的grails.gorm.default.constraints中定义。让我猜猜那里没有定义“电子邮件”,所以你得到了这个例外?

只需从用户中删除“共享:'电子邮件'”,导入就可以正常工作。

有用的链接: http: //mrhaki.blogspot.com.by/2014/03/grails-goodness-combining-constraints.html

于 2017-02-27T17:52:21.453 回答