且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在脚本中使用Grails服务

更新时间:2023-12-05 21:40:58

Getting hold of ApplicationContext and grailsApplication is possible though bootstrap command. Include _GrailsBootstrap script, then call configureApp () or depend on it in order to make ApplicationContext available in script:

includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsBootstrap")

target(loadGames: "The description of the script goes here!") {
   depends(configureApp)

   def listFile = new File('list.txt')

   listFile.eachLine {
      //Once configureApp() called ApplicationContext can be accessed as appCtx
      def result = appCtx.getBean("bggService").search(it)
      println it + " " + result.length()
   }
}

setDefaultTarget(loadGames)

相关阅读

推荐文章