1

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

  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
        }
    }

控制器绑定数据如下:

def save { UserCommand command ->

...
}

此时我收到上述错误消息。我还尝试使用命令对象作为参数保存(UserCommand 命令),但没有任何效果。有人有什么提示吗?

4

1 回答 1

2

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

于 2012-02-28T07:59:12.317 回答