NutzCN Logo
问答 定时任务调用service封装好的方法,可是报错dao对象为空,并且service的方法内有调用activiti的方法,不好把dao对象传过去
发布于 2142天前 作者 qq_39fcc7a4 2652 次浏览 复制 上一个帖子 下一个帖子
标签:
package com.fzzl.hrp.cw.voucher.job;

import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.fzzl.hrp.cw.voucher.bean.CwVoucherPojo;
import com.fzzl.hrp.cw.voucher.disbursement.service.CwDisbursementVoucherService;
import com.sys.framework.service.BaseService;
import com.sys.util.nutz.NutzUtil;
@IocBean
public class CwVoucherOverTimeAutoApproveJob extends BaseService<CwVoucherPojo> implements Job{

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		CwDisbursementVoucherService cwDisbursementVoucherService = new CwDisbursementVoucherService();
		//超过24h未审批的自动审批通过。
		cwDisbursementVoucherService.agreeOverTimeNotApprove();
	}

}
13 回复

通过 @Inject 注入,而不是继承

怎样才能让定时任务调用的时候不把dao对象传到service方法内,就直接保证有dao对象

注入CwDisbursementVoucherService 么?

是的, 直接new是必须死

这个解决了,但是有一个新的问题,在调用activiti的claim方法时,我们自己写的ActivitiUserTaskActivityBehavior类继承了activiti的UserTaskActivityBehavior类,里面获取Ioc获取不到。

public class ActivitiUserTaskActivityBehavior extends UserTaskActivityBehavior {

	Ioc ioc = Mvcs.getIoc();
	XtWorkFlowTaskService xtWorkFlowTaskService = ioc.get(XtWorkFlowTaskService.class);

	public ActivitiUserTaskActivityBehavior(String userTaskId, TaskDefinition taskDefinition) {
		super(userTaskId, taskDefinition);
	}


把ioc的文档看一遍

您的意思是这个类也需要加@IocBean注解是吧,但是还是不行,请大佬教我下吧

以为我这边正常调用是没问题的,但是定时任务调用就会有问题获取不到。

手动获取ioc对象,看这个

package com.sys.activiti.restructure;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.DynamicBpmnConstants;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.activiti.engine.delegate.event.impl.ActivitiEventBuilder;
import org.activiti.engine.history.HistoricIdentityLink;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.helper.SkipExpressionUtil;
import org.activiti.engine.impl.calendar.BusinessCalendar;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;
import org.activiti.engine.impl.task.TaskDefinition;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.apache.bcel.generic.IXOR;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.ioc.loader.combo.ComboIocLoader;
import org.nutz.mvc.Mvcs;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sys.activiti.task.service.XtWorkFlowTaskService;
import com.sys.util.util.DataTypeUtil;

public class ActivitiUserTaskActivityBehavior extends UserTaskActivityBehavior {

//	Ioc ioc = Mvcs.getIoc();
	public  Ioc ioc;
	
	XtWorkFlowTaskService xtWorkFlowTaskService;

	public ActivitiUserTaskActivityBehavior(String userTaskId, TaskDefinition taskDefinition) {
		
		super(userTaskId, taskDefinition);
		try {
			ioc = new NutIoc(new ComboIocLoader("*js", "/mvc", "/ioc", "*anno", "com.sys", "com.fzzl","*tx", "*jedis","*activiti"));
			xtWorkFlowTaskService = ioc.get(XtWorkFlowTaskService.class);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

这个应该属于非MVC下,我是通过new的方法,但是这样太慢了,都扫描了5分钟还没好

这个应该属于非MVC下,我是通过new的方法,但是这样太慢了,都扫描了5分钟还没好

public class ActivitiUserTaskActivityBehavior extends UserTaskActivityBehavior {

//	Ioc ioc = Mvcs.getIoc();
	public  Ioc ioc;
	
	XtWorkFlowTaskService xtWorkFlowTaskService;

	public ActivitiUserTaskActivityBehavior(String userTaskId, TaskDefinition taskDefinition) {
		
		super(userTaskId, taskDefinition);
		try {
			ioc = new NutIoc(new ComboIocLoader("*js", "/mvc", "/ioc", "*anno", "com.sys", "com.fzzl","*tx", "*jedis","*activiti"));
			xtWorkFlowTaskService = ioc.get(XtWorkFlowTaskService.class);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

new毛线呀,用setup的init方法放到静态变量去

哈哈,好尴尬,解决了

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