我尝试了平台-核心-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()
}
}该服务应该返回另一个名为“制度化管理”的grails插件中下拉列表。我想将这个服务列表用于域模型的下拉列表。我应该提到我使用的是动态脚手架。现在,我尝试在域模型中调用此事件:
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: No签名的方法: institutionadmin.Einrichtung.event()适用于参数类型:(java.util.LinkedHashMap)值:[ for :listadmin,topic:testEventBus]可能的解决方案: ident(),for(),for(groovy.lang.Closure),count(),get(java.io.Serializable),print(java.lang.Object)
如果在控制器中调用此事件,一切都很好,并且这个插件的文档描述了我也可以在域模型和服务中调用事件.这个错误方法告诉我,类不知道事件方法。
我还需要配置其他东西吗?
应该用另一种方式来宣布这件事,否则我的错误在哪里?
有人对这个模块有经验吗?
发布于 2013-05-29 13:38:21
event(...)动态方法在类(静态)级别上不可用。
您可以提取grailsEvents spring并交替调用它的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中),并在我的域中使用/注入它,而不是在约束闭包中这样做。
发布于 2013-09-30 18:09:20
我遇到了类似的问题,我想在服务类中使用事件调用,它将调用其他服务类中的侦听器。当我启动我的应用程序时,我得到了我所做的相同的error.What,在BuildConfig.groovy中添加了插件(platform-core: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 >>编译,并重新启动server.It开始工作。也许你可以试试。
https://stackoverflow.com/questions/16551275
复制相似问题