从grails 1.3.7升级到2.0.1后,在验证 Controller 中的命令对象时,我遇到了follwong奇怪的异常。

  groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method org.codehaus.groovy.grails.orm.hibernate.HibernateGormValidationApi#validate.
Cannot resolve which method to invoke for [class at.pdts.etsweb.commandobject.UserCommand, null] due to overlapping prototypes between:
    [class java.lang.Object, interface java.util.List]
    [class java.lang.Object, interface java.util.Map]

    at org.grails.datastore.gorm.InstanceMethodInvokingClosure.call(GormEnhancer.groovy:251)

    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

    at java.lang.Thread.run(Thread.java:662)

我的UserCommand命令对象如下所示:
package at.pdts.etsweb.commandobject

import at.pdts.etsweb.Common
import grails.validation.Validateable

    @Validateable
    class UserCommand {
        String username
        String password
        String firstname
        String lastname
        static constraints = {
            username blank: false, email: true
            password blank: false, minSize: 8, maxSize: 64, validator: Common.passwordValidator
            firstname blank: false
            lastname blank: false
        }
    }

Controller 按以下方式绑定(bind)数据:
def save { UserCommand command ->

...
}

至此,我收到了以上错误消息。我也尝试将命令对象用作参数save(UserCommand command),但没有任何效果。有人暗示吗?

最佳答案

我的解决方法是将命令对象类从/ grails-app / controller移至/ src / groovy。之后,错误消失了。

关于grails - grails升级2.0.1命令对象验证错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9373797/

10-13 05:10