Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails中石英作业的注入服务_Grails_Quartz Scheduler - Fatal编程技术网

Grails中石英作业的注入服务

Grails中石英作业的注入服务,grails,quartz-scheduler,Grails,Quartz Scheduler,使用Grails 2.5.1开发应用程序时,我使用了Grails 2.5.1并成功创建了一个作业,但当我在这个作业中注入服务时,我得到了org.quartz.JobExecutionException:java.lang.NullPointerException 以下是作业代码: class EveryMonthJob { def usersUtilsService static triggers = { cron name: 'EveryOneMonthJob', cronExpres

使用Grails 2.5.1开发应用程序时,我使用了
Grails 2.5.1
并成功创建了一个作业,但当我在这个作业中注入服务时,我得到了
org.quartz.JobExecutionException:java.lang.NullPointerException

以下是作业代码:

class EveryMonthJob {
def usersUtilsService
static triggers = {
    cron name: 'EveryOneMonthJob', cronExpression: "* 31 2 L * ?" 
}

def execute() {

    usersUtilsService.testMe() // getting the exception here 
        }
} 

有许多原因可能不起作用。如果您自己正在创建作业的实例(与Spring创建实例并将其置于依赖项注入之下不同),这将解释为什么引用为null。另一种解释可能是您的属性名称错误

请参阅上的项目。这是一个Grails2.5.1应用程序,它可以实现您所描述的功能,并且运行良好。看看下面哪个是这样的:

class EveryMonthJob {

    // generally I would statically type this property but
    // am leaving it dynamically typed top be consistent with
    // a question being asked...
    def usersUtilsService

    static triggers = {
      simple repeatInterval: 5000l // execute job once in 5 seconds
    }

    def execute() {
        usersUtilsService.testMe() // this works fine
    }
}

NPE是“不能在null对象上调用testMe()”还是其他什么?我还将服务注入到2.5.1 quartz作业中,它们也能工作,所以我怀疑这里可能还有其他问题。伙计们,在grails项目上运行
clean
命令后,它成功地工作了。我认为这个项目需要清理,仅此而已。