Can't access any bean from Quartz Job in Grails

老子叫甜甜 提交于 2019-12-22 13:57:09

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/21225217/cant-access-any-bean-from-quartz-job-in-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!