我无法在doWithDynamicMethod中访问特定服务。
def doWithDynamicMethods = { ctx ->
def nodeDriverProxy = application.getServiceClass('NodeDriverProxyService')
application.domainClasses.each{ cClass ->
delegate.log.warn('cClass: ' + cClass.toString())
cClass.metaClass.cacheInstance = { domainIns->
delegate.log.warn "domain is being cached id: ? with version ?"
nodeDriverProxy.registerUpdate(domainIns.id, domainIns.version)
}
变量nodeDriveProxy为null或者我在访问'application.serviceClasses'时遇到异常我做错了什么?谢谢
答案 0 :(得分:2)
您不希望GrailsServiceClass
,您想要服务实例。您有ctx
变量,即Spring ApplicationContext
,因此它将是
def doWithDynamicMethods = { ctx ->
def service = ctx.nodeDriverProxyService
application.domainClasses.each { cClass ->
delegate.log.warn('cClass: ' + cClass.toString())
cClass.metaClass.cacheInstance = { domainIns ->
delegate.log.warn "domain is being cached id: ? with version ?"
service.registerUpdate(domainIns.id, domainIns.version)
}
}
}