2

I am using services in grails and getting and setting data from services in controllers and there is no problem. I know how to use it... But this problem I can't solve, please help me if you know what is going wrong.

There is a QuartzJob, I schedule from service from controller... Data is stored in PostgreSQL. Using last version of all plugins and 2.3.3 Grails. In code below I just want to print nickname, but I can't get service. Tried to get bean, def grailsApplication but with no success.

Grails plugin for Quartz is quartz:1.0-RC11

class TestJob implements Job{
    def userService

    void execute(org.quartz.JobExecutionContext t) {         
        try {
            println userService.getUserProfile("farko").username
        } catch (Exception ex){
            println ex.printStackTrace()
        }
    }
}

I getting this error

Error | java.lang.NullPointerException: Cannot invoke method getUserProfile() on null object Error | at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77) Error | at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45) Error | at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) Error | at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32) Error | at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) Error | at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) Error | at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) Error | at test.TestJob$$EOTRiFAo.execute(TestJob.groovy:27) Error | at test.TestJob$$DOTRiFAo.execute(Unknown Source) Error | at test.TestJob.execute(TestJob.groovy) Error | at org.quartz.core.JobRunShell.run(JobRunShell.java:207) Error | at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560) null

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
user3213516
  • 71
  • 2
  • 7

1 Answers1

3

You implement Job, but this is rare when using the plugin. Typically you just create a class in grails-app/jobs (either by hand or with the create-job script) with a name that ends in "Job", and the magic happens. Are you creating the classes in src/groovy? You need to use the plugin's conventions to get dependency injection to work.

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • DRY is Grails magic... I think there is some short way to solve this. All examples I see there, using services without any problems. – user3213516 Jan 20 '14 at 07:55
  • http://stackoverflow.com/questions/10640480/grails-2-x-service-injection-in-groovy-src this is how to get DI. But I think there is some other solution. – user3213516 Jan 20 '14 at 09:49