Search code examples
grailsdependency-injectiontaskquartz-schedulerjobs

Accessing grails application config from a quartz job


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, however, doesn't get injected, and is null.

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 :-/

help? 10x


Solution

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

    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
      }