grails 2.2.2 platform-core-plugin域模型中没有方法事件的签名

时间:2013-05-14 19:27:26

标签: events grails grails-platform-core

我通过事件尝试使用platform-core-1.0 rc5插件进行服务。现在我在grails-plugin“listadmin”中编写了一个服务:

package listadmin

class SECO_ListenService {

    @grails.events.Listener(topic='getEntriesOfList', namespace='listadmin')
    def getEntriesOfList(String intnalListName) {
        println "SECO_ListenService"
        def Liste aList = Liste.findByInternal_name(intnalListName)
        return aList.eintrage.toList()
    }
}

此服务应返回名为“institutionadmin”的其他grails-plugin中的下拉列表。我想使用此服务列表来下载域模型。我应该提一下,我使用动态脚手架。现在我尝试在域模型中调用此事件:

package institutionadmin
import org.springframework.dao.DataIntegrityViolationException
class Einrichtung {

    Long einrichtungs_type
    Long type_of_conzept
    int anzahl_gruppen
    int anzahl_kinder_pro_Gruppe
    String offnungszeiten
    static hasMany = [rooms : Raum]
    static constraints = {
        def aList = []
        def reply = event(for:"listadmin", topic:"getEntriesOfList", data:"einrichtung_type").waitFor()

        aList = reply.value.toList()
        einrichtungs_type(inList: aList)
    }
}

如果我尝试运行此应用程序,则会出现以下错误:

  

由MissingMethodException引起:没有方法签名:institutionadmin.Einrichtung.event()适用于参数类型:(java.util.LinkedHashMap)值:[[for:listadmin,topic:testEventBus]]   可能的解决方案:ident(),every(),every(groovy.lang.Closure),count(),get(java.io.Serializable),print(java.lang.Object)

如果在控制器中调用此事件一切都很好,这个插件的文档描述我也可以在域模型和服务中调用事件......这个错误方法告诉我,该类不知道事件方法。

我还需要配置其他内容吗?

应该以另一种方式召唤事件或我的错误在哪里?

有没有人使用这个模块?

2 个答案:

答案 0 :(得分:3)

event(...)动态方法在类(静态)级别上不可用。

您可以拉grailsEvents spring bean并交替调用其event()方法。你仍然需要静态地从应用程序上下文中获取bean。

您也可以使用自定义验证器,因为您可以将当前域实例作为参数获取,该参数应该注入event()方法。

类似的东西:

static myList = []
static constraints = {
    einrichtungs_type validator: { value, instance ->
        if(!myList){
            // cache it the first time you save/validate the domain
            // I would probably recommend you NOT to do this here though in 
            // real life scenario
            def reply = instance.event('blabla').get()
            myList = reply.value.toList()
        }

        return value in myList
    }
}

无论如何,在我的情况下,我可能会将列表加载到别处(例如在Bootstrap.groovy中)并使用它/在我的域中注入它而不是在约束闭包中。

答案 1 :(得分:0)

我遇到了类似的问题,我想在服务类中使用事件调用,该服务类将调用其他服务类中的侦听器。当我启动我的应用程序时,我得到了同样的错误。我做的是,在platform-core:1.0.RC5中添加了插件(BuildConfig.groovy)条目,如下所示

plugins {

    build(":tomcat:$grailsVersion",
        ":platform-core:1.0.RC5") {
        export = false
    }
    compile ':platform-core:1.0.RC5'
    runtime ':platform-core:1.0.RC5'
}

然后我跑了grails>干净和grails>编译该项目并重新启动服务器。它开始工作。你可以尝试一下。

相关问题