activiti监听器配置

在配置Activiti监听器时遇到'couldn't instantiate class xxx'的错误。通过在线设计工作流模型并部署发布,可以解决这个问题。监听器可能不被Spring管理,使用静态类实例化服务。开发过程中,若出现异常,需重启服务并重新发布工作流。

activiti监听器

出现报错 

 couldn't instantiate class xxx
 

通过工作流的模型在线设计  http://127.0.0.1/activiti/model-manage

 分别配置执行监听器 任务监听器

模型有历史版本的功能 所以 点击部署发布后  工作发布者

新 编辑/提交/增加工作流程  才能生效 如果不刷新页面 这里开发时可能会莫名其妙出现  couldn't instantiate class xxx 重启服务 重新发布工作流即可

这个监听器好像是不属于spring管理的 这里直接用静态类实例化相关的服务 


import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;

import java.util.Date;


@Slf4j
public class xxx implements ExecutionListener, TaskListener {

    @Override
    public void notify(DelegateExecution delegateExecution) throws Exception {
        String tableId = (String) delegateExecution.getVariable("tableId");
        SafetyInspectionService safetyInspectionService = SpringUtil.getBean(SafetyInspectionService.class);
        SafetyInspection safetyInspection = new SafetyInspection();
        safetyInspection.setId(tableId);
        safetyInspection.setUpdateTime(new Date());
        HistoryIdentityService historyIdentityService = SpringUtil.getBean(HistoryIdentityService.class);
        String uid = historyIdentityService.findUserIdByProcInstId(ActivitiConstant.PARTICIPANT_TYPE, delegateExecution.getId());
        if (uid != null && !uid.isEmpty()) {
            safetyInspection.setAcceptBy(uid);
            safetyInspectionService.updateById(safetyInspection);
        }
        /** execution Id */
//        String getId();7
        print(delegateExecution.getId());
//        /**  流程实例id*/
//        String getProcessInstanceId();
        print(delegateExecution.getProcessInstanceId());
//
//        /** 这个比较有用 主要就是start、end、take  */
//        String getEventName();
        print(delegateExecution.getEventName());
//
//        /**
//         *  业务id,已经废弃的用法
//         */
//        String getBusinessKey();
        print(delegateExecution.getBusinessKey());
//
//        /**
//         * 业务id   */
//        String getProcessBusinessKey();
        print(delegateExecution.getProcessBusinessKey());
//
//        /**
//         * 流程定义id
//         */
//        String getProcessDefinitionId();
        print(delegateExecution.getProcessDefinitionId());
//
//        /**
//         * 获取父id,并发的时候有用
//         */
//        String getParentId();
        print(delegateExecution.getParentId());
//
//        /**
//         * 获取当前的 Activityid
//         */
//        String getCurrentActivityId();
//        测试开始节点id sid-AF336074-AECD-4DB0-8E4D-26A741732A7F
        print(delegateExecution.getCurrentActivityId());


//
//        /**
//         * 获取当前的 Activity name
//         */
//        String getCurrentActivityName();
//
        print(delegateExecution.getCurrentActivityName());
//        /**
//         * 获取TenantId 当有多个TenantId 有用
//         */
//        String getTenantId();
//
        print(delegateExecution.getTenantId());
//        /**
//         * 这个非常有用吧。当拿到EngineServices 对象所有的xxxService都可以拿到。
//         */
//        EngineServices getEngineServices();
//        EngineServices ob = delegateExecution.getEngineServices();
    }

    private void print(String s) {
        System.out.println();
        System.out.println(s);
        System.out.println();

    }

    @Override
    public void notify(DelegateTask delegateTask) {
        // TODO Auto-generated method stub
        String eventName = delegateTask.getEventName();
        if ("create".endsWith(eventName)) {
            System.out.println("create=========");
        } else if ("assignment".endsWith(eventName)) {
            System.out.println("assignment========");
        } else if ("complete".endsWith(eventName)) {
            System.out.println("complete===========");
        } else if ("delete".endsWith(eventName)) {
            System.out.println("delete=============");
        }


    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值