Reputation: 105
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: dataSource)
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
Upvotes: 1
Views: 2617
Reputation: 105
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)
Upvotes: 0
Reputation: 35904
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.
Upvotes: 2