一、全局监听器
它是引擎范围的事件监听器,可以捕获所有的Activiti事件。
事件类型
ActivitiEventType 枚举类中包含全部事件类型
配置方式(选)
-
spring bean配置
-
全局配置类设置(config.setEventListeners())
config.setEventListeners(Collections.singletonList(new MyGlobalEventListener())); -
启动流程动态添加并且可以指定要监听的事件类型(推荐)
runtimeService.addEventListener(new MyGlobalEventListener(), ActivitiEventType.TASK_CREATED, ActivitiEventType.TASK_ASSIGNED, ActivitiEventType.TASK_COMPLETED); -
class
-
expression
-
delegateExpression
日志监听器
全局配置类开启:config.setEnableDatabaseEventLogging(true);
开启后可以在 act_evt_log表中看到相关的日志记录。
代码实现

xml文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
<process id="global-listener" name="全局事件监听器" isExecutable="true">
<documentation>测试全局事件监听器</documentation>
<extensionElements>
<!-- 需要高版本的插件才能不爆红 支持class expression delegateExpression 配置方式 -->
<!-- <activiti:eventListener entityType="task" delegateExpression="${myGlobalEventListener}"/>-->
</extensionElements>
<startEvent id="sid-30244641-2a1c-43e5-af5b-e77db43488bf" name="开始">
<documentation>开始了</documentation>
</startEvent>
<userTask id="sid-9e62413f-e04f-4c81-8d0c-e73f17e125ec" name="节点1"
activiti:assignee="${applyUserId}" activiti:candidateUsers="${candidateUsers}" activiti:candidateGroups="${candidateGroups}">
<documentation>任务节点1</documentation>
</userTask>
<sequenceFlow id="sid-1af5e647-b03c-4b12-807d-4171dfdf7ae9" sourceRef="sid-30244641-2a1c-43e5-af5b-e77db43488bf" targetRef="sid-9e62413f-e04f-4c81-8d0c-e73f17e125ec" name="顺序流1">
<documentation>顺序流1了</documentation>
</sequenceFlow>
<userTask id="sid-d903cb09-56c2-4cfe-bd05-5ba0699539d0" name="节点2">
<documentation>任务节点2</documentation>
</userTask>
<sequenceFlow id="sid-300ac02e-dc56-4988-bdd4-fd94a5bb71f7" sourceRef="sid-9e62413f-e04f-4c81-8d0c-e73f17e125ec" targetRef="sid-d903cb09-56c2-4cfe-bd05-5ba0699539d0" name="顺序流2">
<documentation>顺序流2了</documentation>

本文介绍了如何在Activiti中配置全局监听器,包括事件类型的选择、使用springbean配置、日志监听的启用,以及通过XML文件和Java代码实现监听器的详细步骤和测试流程。
最低0.47元/天 解锁文章
1151

被折叠的 条评论
为什么被折叠?



