从石英作业中的config.groovy(在conf目录中)访问变量

时间:2014-12-12 20:32:13

标签: grails groovy config quartz-scheduler

我在config.groovy中有一个hashmap,我希望从groovy中的Quartz Job访问

Map<String,Map<String, String>> projectname.config.Map1 = new HashMap<String, Map<String, String>>();

我想在下面的Quartz Job中访问:

import projectname.grails-app.conf.*;

class TrialJob {

    static triggers = {            
        simple repeatInterval: 10000l // execute job once in 5 seconds          
    }

    def execute() {

        def Application

        Map<String,Map<String, String>> Holder = Application.projectname.config.Map1
        log.info()        
    }
}

1 个答案:

答案 0 :(得分:0)

如果您使用

Config.groovy中声明地图
projectname.config.Map1 = []

(大概你也想在地图上放一些东西),那么你应该可以从你的工作类中检索它,如下所示

import org.codehaus.groovy.grails.commons.GrailsApplication

class TrialJob {
    GrailsApplication grailsApplication

    static triggers = {            
        simple repeatInterval: 10000l // execute job once in 5 seconds          
    }

    def execute() {
        Map<String,Map<String, String>> map = grailsApplication.config.projectname.config.Map1     
    }
}