Activiti监听器
ExecutionListener:监听全局事件,start(流程启动),end(流程结束),take(经过连线)
TaskListener:监听节点事件,assignment(任务分配),create(任务创建),complete(任务完成),delete(任务被删除),all(监听所有事件)
ExecutionListener的用法:
# 监听start和end定义在根路径
<process id="vacationRequestDemo" name="Vacation request">
<extensionElements>
<activiti:executionListener event="start" class="com.ltp.activitidemo.activiti.listener.MyExecutionListener" />
<activiti:executionListener event="end" class="com.ltp.activitidemo.activiti.listener.MyExecutionListener" />
</extensionElements>
</process>
监听连线事件,当流程经过这条连线时就会被触发。
<sequenceFlow id="flow5" sourceRef="requestApprovedDecision" targetRef="adjustVacationRequestTask">
<extensionElements>
<activiti:executionListener event="take" class="com.ltp.activitidemo.activiti.listener.MyExecutionListener" />
</extensionElements>
</sequenceFlow>
MyExecutionListener类:
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
public class MyExecutionListener implements ExecutionListener {
public void notify(DelegateExecution execution) {
String eventName = execution.getEventName();
if ("start".equals(eventName)) {
System.out.println("start=========流程启动");
}else if ("end".equals(eventName)) {
System.out.println("end=========流程结束");
} else if("take".equals(eventName))
System.out.println("take ======经过连线");
}
}
TaskListener的用法:
<userTask id="adjustVacationRequestTask" name="Adjust vacation request">
<extensionElements>
<activiti:taskListener event="all" class="com.ltp.activitidemo.activiti.listener.MyTaskListener" />
</<extensionElements>
</userTask>
MyTaskListener类
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
public class MyTaskListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
String eventName = delegateTask.getEventName();
if("create".endsWith(eventName))
System.out.println("task create===");
else if("assignment".endsWith(eventName))
System.out.println("task assignment===");
else if("complete".endsWith(eventName))
System.out.println("task complete===");
else if("delete".endsWith(eventName))
System.out.println("task delete===");
}
}
注意修改了流程文件就需要重新部署,再启动流程,关于部署和启动流程可以看上一篇博客。
https://blog.csdn.net/Bugggget/article/details/88583607