<h6>---以下内容为公司内部流程小白测试笔记,非官方正式文档---</h6> 流程监听 按监听类型分为:**执行监听**和**任务监听** **执行监听**使用的java类需要实现接口org.activiti.engine.delegate.ExecutionListener **任务监听**使用的java类需要实现接口org.activiti.engine.delegate.TaskListener ---- 执行监听用于配置在全局、节点间连线上 任务监听用于配置在节点上 ---- 流程设计 ![](https://img.kancloud.cn/89/57/89573529d3aabe8c8cb43eeba7db105c_1138x541.png) 配置全局监听 ![](https://img.kancloud.cn/fe/0d/fe0d683a139b15ec0f34434aba2110bb_1141x372.png) 配置节点2的监听 ![](https://img.kancloud.cn/30/fb/30fb2a5738865a4b30a7dacabffc1c41_1658x303.png) 配置节点间连线监听 ![](https://img.kancloud.cn/e9/97/e997587cd1950d2fbd71b51a757e5b70_1662x372.png) 对应监听配置如下: ![](https://img.kancloud.cn/42/06/420654cd080c45f3090dedbb7393a72e_1601x251.png) 对应java代码如下: ~~~ public class OverAllStartListener implements ExecutionListener { @Override public void notify(DelegateExecution execution) throws Exception { System.out.println("=============流程开始监听执行了============"); System.out.println(execution.getProcessInstanceId()); System.out.println(execution.getVariable("applyUserId")); System.out.println(execution.getVariable("CREATE_BY")); } } ~~~ ~~~ public class OverAllEndListener implements ExecutionListener { @Override public void notify(DelegateExecution execution) throws Exception { System.out.println("=============流程结束监听执行了============"); System.out.println(execution.getProcessInstanceId()); System.out.println(execution.getVariable("applyUserId")); System.out.println(execution.getVariable("CREATE_BY")); } } ~~~ ~~~ public class NodeLineListener implements ExecutionListener { @Override public void notify(DelegateExecution execution) throws Exception { System.out.println("=============流程连线监听执行了============"); System.out.println(execution.getProcessInstanceId()); System.out.println(execution.getVariable("applyUserId")); System.out.println(execution.getVariable("CREATE_BY")); } } ~~~ ~~~ public class NodeListener implements TaskListener { @Override public void notify(DelegateTask delegateTask) { System.out.println("=============流程节点监听执行了============"); System.out.println(delegateTask.getProcessInstanceId()); System.out.println(delegateTask.getVariable("applyUserId")); System.out.println(delegateTask.getVariable("CREATE_BY")); } } ~~~ 配置表单,发布流程,测试,控制台打印如下: ``` =============流程开始监听执行了============ 140092 admin admin =============流程连线监听执行了============ 140092 admin admin =============流程节点监听执行了============ 140092 admin admin =============流程结束监听执行了============ 140092 admin admin ``` 任务监听 事件类型支持的类型有: * create: 任务被创建,并且所有的属性都被设置好后。 * assignment: 任务被委派给某人后。注意: 当流程执行到达一个userTask时,会先触发一个assignment事件,再触发create事件。 * complete:在任务完成后,且被从运行时数据(runtime data)中删除前触发。 如果节点是需要签收的节点,则先触发create事件,这块报了一个错,签收不通过!暂放