NutzCN Logo
问答 nutz-mini 定时任务job依赖注入为空
发布于 50天前 作者 qq_0e08b035 153 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
package cn.wizzer.app.task.commons.ext.quartz.job;

import cn.wizzer.app.sys.modules.services.SysTaskService;
import cn.wizzer.app.web.commons.mqtt.HeartbeatServerMQTT;
import cn.wizzer.app.web.commons.mqtt.PushCallback;
import com.alibaba.fastjson.JSON;
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.HashMap;
import java.util.Map;
@IocBean
public class IntellindustJob implements Job {

    private static final Log log = Logs.get();

    @Inject
    protected SysTaskService sysTaskService;

    @Inject
    protected HeartbeatServerMQTT heartbeatServerMQTT;


    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("执行发送心跳接口-start");
        String taskId = context.getJobDetail().getKey().getName();
        heartbeatServerMQTT.sendMessageData();
        sysTaskService.update(Chain.make("exeAt", (int) (System.currentTimeMillis() / 1000)).add("exeResult", "执行成功"), Cnd.where("id", "=", taskId));
    }




}

@IocBean
public class HeartbeatServerMQTT {

HeartbeatServerMQTT 的IocBean注入进来后连sysTaskService也变成空的了
之前注入
@Inject
protected PropertiesProxy conf;
在定时任务里依赖注入也都会变空的

9 回复

检查一下JobFactory

JobFactory 这个要怎么检查

这是nutzwk-mini吧?

嗯是的nutzwk-mini @wendal

看看有没有quartz.js

有的 但是被封装在jar包里

var ioc = {
   "scheduler" :{
      "type" :"org.quartz.Scheduler",
      "factory" :"org.quartz.impl.StdSchedulerFactory#getDefaultScheduler",
      "events" :{
         "create" :"start",
         "depose" :"shutdown"
      },
      "fields" :{
         "jobFactory" :{
            "refer" :"jobFactory"
         }
      }
   },
   "jobFactory" :{
      "type" :"org.nutz.integration.quartz.NutQuartzJobFactory",
      "args" :[{
         "refer" :"$ioc"
      }]
   },
   "nutQuartzCronJobFactory" :{
      "type" :"org.nutz.integration.quartz.NutQuartzCronJobFactory",
      "events" :{
         "create" :"init"
      },
      "fields" :{
         "scheduler" :{
            "refer" :"scheduler"
         },
         "conf" :{
            "refer" :"@confName"
         }
      }
   },
   "quartzManager" : {
	   "type" :"org.nutz.integration.quartz.QuartzManagerImpl",
	   "fields" :{
	         "scheduler" :{
	            "refer" :"scheduler"
	         }
	    }
   }
};

那估计是因为mainPackage没有涵盖这个package, 看看main方法是怎样的?

我看我写的都在这各包下面

public static void main(String[] args) throws Exception {
        NbApp nb = new NbApp().setArgs(args).setPrintProcDoc(true);
        nb.getAppContext().setMainPackage("cn.wizzer");
        nb.run();
    }

日志调到debug,然后搜IntellindustJob 看看吧

添加回复
请先登陆
回到顶部