无法从Grails中的Quartz Job访问任何bean [英] Can't access any bean from Quartz Job in Grails
问题描述
我正在使用Grails中的服务,并从控制器中的服务获取和设置数据,这没有问题.我知道如何使用...但是这个问题我无法解决,如果您知道出了什么问题,请帮助我.
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.
有一个QuartzJob,我从控制器的服务中进行调度...数据存储在PostgreSQL中.使用所有插件的最新版本和2.3.3 Grails.在下面的代码中,我只想打印昵称,但无法获得服务.试图获取bean,def grailsApplication但没有成功.
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.
用于Quartz的Grails插件是石英:1.0-RC11
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()
}
}
}
我收到此错误
错误| java.lang.NullPointerException:无法调用方法 空对象上的getUserProfile()错误在 org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77) 错误在 org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45) 错误在 org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 错误在 org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32) 错误在 org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 错误在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) 错误在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 错误在test.TestJob $$ EOTRiFAo.execute(TestJob.groovy:27)错误| 在test.TestJob $$ DOTRiFAo.execute(未知源)错误|在 test.TestJob.execute(TestJob.groovy)错误|在 org.quartz.core.JobRunShell.run(JobRunShell.java:207)错误|在 org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:560) 空
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
推荐答案
您实现了Job
,但这在使用插件时很少见.通常,您只需要在grails-app/jobs
中创建一个类(通过手工或使用create-job
脚本),其名称以"Job"结尾,那么魔术就发生了.您要在src/groovy
中创建类吗?您需要使用插件的约定才能使依赖项注入起作用.
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.
这篇关于无法从Grails中的Quartz Job访问任何bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!