从石英作业访问Grails应用程序配置 [英] Accessing grails application config from a quartz job

查看:84
本文介绍了从石英作业访问Grails应用程序配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用grails 2.4.2,quartz:1.0.2,我试图访问配置属性

Using grails 2.4.2, quartz:1.0.2, I'm trying to gain access to configuration properties

class MyJob {
  def grailsApplication
  int propA
  def MyJob() {
    propA = grailsApplication.config.foo.bar.propAVal
  }
  ...
}

grailsApplication不会被注入,并且为空.

grailsApplication, however, doesn't get injected, and is null.

无法从Grails中的Quartz Job访问任何bean 应该与此有关,但是我并没有真正看到标记的答案如何解决OP的问题:-/

Can't access any bean from Quartz Job in Grails supposedly relates to this, but I don't really see how the marked answer resolves the OP's question :-/

有帮助吗? 10倍

推荐答案

问题可能是您正在构造函数中访问grailsApplication,而尚未注入它.

The problem is probably that you are accessing grailsApplication in constructor, where it's not injected yet.

我建议转储无用的类属性int propA并采用这种方式:

I recommend to dump useless class property int propA and do it this way:

  def grailsApplication

  def execute() {
    def propA = grailsApplication.config.foo.bar.propAVal         
    ... 
    //use propA for something
  }

这篇关于从石英作业访问Grails应用程序配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆