NutzCN Logo
问答 nutzwk的任务调度 使用redis注入出错
发布于 65天前 作者 baocj 138 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
/**
	 * 把客流信息写入到redis
	 */
	@Aop("redis")
	private void saveKlData2Redis(String sn, String content) {
		long a = System.currentTimeMillis();

		log.info(jedis().info());
		jedis().set("nutzwk:GetKlDataJob:" + sn, content);

		long b = System.currentTimeMillis();
		log.info("saveKlData2Redis time:" + (b - a) + "ms");
	}
[INFO ] 18:58:55.205 cn.wizzer.app.task.commons.ext.quartz.job.GetKlDataJob.execute(GetKlDataJob.java:48) - {"page":"1","total":"1","records":"1","result":"ok","msg":"","rows":[{"num":"1","sn":"EFDD9AF3","dt_data":"2018-05-4","dt_upload":"","in_dat":"49","out_dat":"43","bat_voltage":"0","bat_percent":"0","charge_state":"0","focus_state":"0"}]}
[ERROR] 18:58:55.205 org.quartz.core.JobRunShell.run(JobRunShell.java:211) - Job e3e8b23888ec4846b234a71f0ca95112.e3e8b23888ec4846b234a71f0ca95112 threw an unhandled Exception: 
java.lang.NullPointerException
	at cn.wizzer.app.task.commons.ext.quartz.job.GetKlDataJob.saveKlData2Redis(GetKlDataJob.java:63)
	at cn.wizzer.app.task.commons.ext.quartz.job.GetKlDataJob.execute(GetKlDataJob.java:50)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
[ERROR] 18:58:55.205 org.quartz.core.ErrorLogger.schedulerError(QuartzScheduler.java:2401) - Job (e3e8b23888ec4846b234a71f0ca95112.e3e8b23888ec4846b234a71f0ca95112 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException
	at cn.wizzer.app.task.commons.ext.quartz.job.GetKlDataJob.saveKlData2Redis(GetKlDataJob.java:63)
	at cn.wizzer.app.task.commons.ext.quartz.job.GetKlDataJob.execute(GetKlDataJob.java:50)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	... 1 more
7 回复

GetKlDataJob 加@IocBean没?

package cn.wizzer.app.task.commons.ext.quartz.job;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.http.Http;
import org.nutz.http.Response;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Times;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.alibaba.dubbo.config.annotation.Reference;
import cn.wizzer.app.sys.modules.services.SysTaskService;
import static org.nutz.integration.jedis.RedisInterceptor.jedis;
@IocBean
public class GetKlDataJob implements Job {

	private static final Log log = Logs.get();
	@Inject
	@Reference
	protected SysTaskService sysTaskService;

	public void execute(JobExecutionContext context) throws JobExecutionException {
		JobDataMap data = context.getJobDetail().getJobDataMap();
		String taskId = context.getJobDetail().getKey().getName();
		String url = "http://webservice.ywacn.com/dataport.aspx?cmd=getdatalist&password=1";

		Map<String,Object> para = new HashMap<String,Object>();
		String sn = "EFDD9AF3";
		String dt = Times.sD(new Date());
		para.put("sn", sn);
		para.put("dt", dt);
		para.put("type", "month");

		Response rsp = Http.get(url, para, 0);

		log.info(rsp.getStatus());
		log.info(rsp.getContent());

		saveKlData2Redis(sn, rsp.getContent());

		sysTaskService.update(Chain.make("exeAt", (int) (System.currentTimeMillis() / 1000)).add("exeResult", "执行成功"),
				Cnd.where("id", "=", taskId));
	}

	/**
	 * 把客流信息写入到redis
	 */
	@Aop("redis")
	private void saveKlData2Redis(String sn, String content) {
		long a = System.currentTimeMillis();

		log.info(jedis().info());
		jedis().set("nutzwk:GetKlDataJob:" + sn, content);

		long b = System.currentTimeMillis();
		log.info("saveKlData2Redis time:" + (b - a) + "ms");
	}

}

是jedis()返回null了吗?

@Aop标注的方法不能是private的

private void saveKlData2Redis

看来还是基础功不够,谢谢

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