务实的石英石英

时间:2012-12-30 19:06:28

标签: grails quartz-scheduler

我有问题。我想创建一个Job但不是在应用程序启动时。 我想从pingServcie调用方法但是为null。

这是我的代码:

工作班

class MyJob implements Job {

def pingService

 @Override
    void execute(JobExecutionContext context) throws JobExecutionException {
      pingService.checkPing()
   }
}

我在某处读到了我需要使用我的Service类的bean,因为Spring Autowire在这种情况下不起作用,所以我创建它(我从不使用bean,所以如果这是正确的话我不会这样做)。 我创建了resources.xml而不是resources.groovy

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  <bean name="pingService" class="inzynierka.PingService" />
</beans>

但这不起作用。

最后,我做了类似的事。

class MyJob implements Job {

def PingService pingService

 @Override
    void execute(JobExecutionContext context) throws JobExecutionException {
      JobDataMap dataMap = context.getJobDetail().getJobDataMap();
      pingService = dataMap.getWrappedMap().get("pingService")
      pingService.checkPing()
   }
}

我像这样在不同的班级传递params

job.getJobDataMap().put("pingService", pingService)

它有效。

0 个答案:

没有答案