开发者

Grails ApplicationHolder replacement

I would like to ask what should I replace ApplicationHolder to get the grailapplication. I have the following grails script to run a method in a grails service.

import org.codehaus.groovy.grails.commons.ApplicationHolder
import de.rvgmbh.nemesis.migration.service.MasterDataMigrationService
def ctx = ApplicationHolder.getApplication().getMainContext()
def dataSource = ctx.getBean("dataSourceSybase")
def masterDataMigrationService = new MasterDataMigrationService(dataSourceSybase: dataSou开发者_JAVA百科rce)
if (masterDataMigrationService != null) {
    masterDataMigrationService.partnerMigration() 
}
else {
  println "ist leider etwas falsches passiert"
}

dataSourceSybase is a spring bean in resources.groovy. What should I do to replace ApplicationHolder since it is now deprecated. Thanks in advance


If this is a script you run with the run-script command, the context is already injected into it for you. Just use the variable ctx. No need to define it.


includeTargets << grailsScript("Bootstrap")

target(main: "master data migration service") {
// TODO: Implement script here
depends(bootstrap)
bootstrap()
def dataSource = appCtx.getBean("dataSourceSybase")
def masterDataMigrationService = new MasterDataMigrationService(dataSourceSybase: dataSource)

if (masterDataMigrationService != null) {
  masterDataMigrationService.partnerMigration()
}
else {
 println "ist leider etwas falsches passiert"
}

} 


setDefaultTarget(main)

The following is what I try to convert into gant script. It can not run

includeTargets << grailsScript("Bootstrap")

target(main: "master data migration service") {
// TODO: Implement script here
bootstrap()
def dataSource = appCtx.getBean("dataSourceSybase")
def masterDataMigrationService = new MasterDataMigrationService(dataSourceSybase: dataSource)

if (masterDataMigrationService != null) {
  masterDataMigrationService.partnerMigration()
}
else {
    println "ist leider etwas falsches passiert"
}

}
setDefaultTarget(main)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜