Reputation: 71
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
Upvotes: 2
Views: 1184
Reputation: 75671
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.
Upvotes: 3