我正在尝试在以下 Grails 脚本中使用 Grails 服务
includeTargets << grailsScript("_GrailsInit")
target(loadGames: "The description of the script goes here!") {
def listFile = new File('list.txt')
listFile.eachLine {
def result = ctx.getBean("bggService").search(it)
println it + " " + result.length()
}
}
setDefaultTarget(loadGames)
我已经看到大约十几个不同的网页,每个网页都提供不同的ctx
appCtx
, 和applicationContext
(以及许多其他) 组合作为建议,但是它们都不起作用。通常他们会抱怨我尝试使用的上下文变量不存在。
为什么 Grails 不能像在控制器中一样使用脚本中的服务?
在 Grails 脚本中使用 Grails 服务的正确方法是什么?