Events grails 2.2.2平台核心插件域模型中无方法事件签名
我尝试使用platform-core-1.0rc5插件按事件提供服务。现在,我在grails插件“listadmin”中编写了一个服务: 该服务应该返回一个列表,以便在另一个名为“institutionadmin”的grails插件中下拉。我想用这个服务列表来下拉一个域模型。我应该提到,我使用动态脚手架。现在,我尝试在域模型中调用此事件:Events grails 2.2.2平台核心插件域模型中无方法事件签名,events,grails,grails-platform-core,Events,Grails,Grails Platform Core,我尝试使用platform-core-1.0rc5插件按事件提供服务。现在,我在grails插件“listadmin”中编写了一个服务: 该服务应该返回一个列表,以便在另一个名为“institutionadmin”的grails插件中下拉。我想用这个服务列表来下拉一个域模型。我应该提到,我使用动态脚手架。现在,我尝试在域模型中调用此事件: package institutionadmin import org.springframework.dao.DataIntegrityViolationE
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)
如果在控制器中调用此事件,一切正常,并且此插件的文档说明我也可以在域模型和服务中调用事件。。。这个错误方法告诉我,类不知道事件方法
我还需要配置其他东西吗
你应该用另一种方式来称呼这个事件,还是我的错误在哪里
有人使用过此模块吗?类(静态)级别上没有事件(…)
动态方法
您可以拉取grailEvents
Springbean,或者调用其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中),并在我的域中使用它/注入它,而不是在约束闭包中使用它。我面临类似的问题,我想在服务类中使用事件调用,该服务类将调用其他服务类中的侦听器。当我启动我的应用程序时,我遇到了同样的错误。我所做的是,在BuildConfig.groovy
中添加了插件(platformcore:1.0.RC5
)条目,如下所示
plugins {
build(":tomcat:$grailsVersion",
":platform-core:1.0.RC5") {
export = false
}
compile ':platform-core:1.0.RC5'
runtime ':platform-core:1.0.RC5'
}
然后,我在该项目上运行grails>clean和grails>compile,并重新启动了服务器。也许你可以试一试
plugins {
build(":tomcat:$grailsVersion",
":platform-core:1.0.RC5") {
export = false
}
compile ':platform-core:1.0.RC5'
runtime ':platform-core:1.0.RC5'
}