SpringBoot整合Activiti7——错误事件(十一)

news/2024/5/19 1:49:56 标签: spring boot, java, 流程图

文章目录

  • 错误事件
    • 开始事件
    • 边界事件
    • 结束事件
    • 代码实现
      • 开始事件
        • xml文件
        • 测试流程
        • 流程执行步骤
      • 边界与结束事件
        • xml文件
        • 自定义错误监听器
        • 测试流程
        • 流程执行步骤


错误事件

好像都是中断的。非中断没测出来!!!

<!-- 定义错误 -->
<error id="error1" name="errorCode1" errorCode="123456"/>
<error id="error2" name="errorCode2" errorCode="123456"/>

开始事件

开始事件只能在事件子流程中被触发,也不能用于启动流程,总是中断的。

可以用于捕获工作流启动时可能出现的各种错误情况,并根据具体的业务需求进行相应的处理。

<!-- 错误开始事件 -->
<startEvent id="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" name="错误开始事件">
  <!-- 引用错误码 -->
  <errorEventDefinition errorRef="error1"/>
</startEvent>

边界事件

总是用于用户任务或子流程上。

当某个任务发生错误时,可以通过错误边界事件来捕获并处理该错误,以保证流程的正常执行。

<!-- 错误边界事件1 非中断 -->
<boundaryEvent id="sid-ef65efec-11aa-4c72-98c5-3cc42a2a8229" attachedToRef="sid-7f48d1e2-a7e5-4717-ad18-cbc5a78b8113" cancelActivity="false" name="错误边界事件1">
  <!-- 引用错误码 -->
  <errorEventDefinition errorRef="error1"/>
</boundaryEvent>

结束事件

错误结束事件就是流程抛出一个bpmn错误。然后被工作流的错误边界事件获取。

错误结束事件会在流程到达错误结束事件的时候抛出错误,并结束当前的流程分支。错误可以使用匹配的错误边界事件捕获。如果找不到匹配的错误边界事件,将会抛出异常。

<!-- 错误结束事件 -->
<endEvent id="sid-1600e3d8-61f9-428f-82c8-c048ef84c774" name="错误结束事件">
  <!-- 引用错误码 -->  
  <errorEventDefinition errorRef="error1"/>
</endEvent>

代码实现

开始事件

错误开始事件针对某个事件子流程触发。(虚线子流程框)
在这里插入图片描述

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">
  <!-- 定义错误 -->
  <error id="error1" name="errorCode1" errorCode="123456"/>
  <process id="error-start" name="错误开始事件" isExecutable="true">
    <documentation>错误开始事件流程</documentation>
    <!-- 开始事件 -->
    <startEvent id="sid-0347a044-9d2e-465b-a449-eb6699044ae4" name="开始事件"/>
    <!-- 服务任务1抛出异常 -->
    <serviceTask id="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" activiti:exclusive="true" name="服务任务1" activiti:delegateExpression="${myThrowErrorDelegateListener}"/>
    <!-- 结束事件 -->
    <endEvent id="sid-2efe3807-4285-416c-a2b7-c3827ec433d2" name="结束事件"/>
    <!-- 子流程 triggeredByEvent表示被事件触发 -->
    <subProcess id="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" triggeredByEvent="true" activiti:exclusive="true">
      <!-- 错误开始事件 -->
      <startEvent id="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" name="错误开始事件">
        <!-- 引用错误码 -->
        <errorEventDefinition errorRef="error1"/>
      </startEvent>
      <!-- 子流程服务任务 -->
      <serviceTask id="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" activiti:exclusive="true" name="子流程服务任务" activiti:delegateExpression="${myServiceTaskListener}"/>
      <!-- 子流程结束事件 -->
      <endEvent id="sid-35fbe381-270f-4ade-bf1b-1e32c289f946" name="子流程结束事件"/>
      <sequenceFlow id="sid-36a022c4-ff28-44f7-8694-b23cf7592b68" sourceRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" targetRef="sid-35fbe381-270f-4ade-bf1b-1e32c289f946"/>
      <sequenceFlow id="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2" sourceRef="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" targetRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa"/>
    </subProcess>
    <sequenceFlow id="sid-3747e8f1-b5c6-4b83-b8af-c74038303170" sourceRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" targetRef="sid-2909cd9a-c18a-429b-be89-4543b6524bbc"/>
    <sequenceFlow id="sid-b3c67896-5be8-4c59-b046-4c4affb36555" sourceRef="sid-0347a044-9d2e-465b-a449-eb6699044ae4" targetRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a"/>
    <!-- 服务任务2 -->
    <serviceTask id="sid-2909cd9a-c18a-429b-be89-4543b6524bbc" activiti:exclusive="true" name="服务任务2" activiti:delegateExpression="${myServiceTaskListener}"/>
    <sequenceFlow id="sid-bff0ca04-cd48-4aa9-8405-66e63124e59b" sourceRef="sid-2909cd9a-c18a-429b-be89-4543b6524bbc" targetRef="sid-2efe3807-4285-416c-a2b7-c3827ec433d2"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_error">
    <bpmndi:BPMNPlane bpmnElement="error-start" id="BPMNPlane_error">
      <bpmndi:BPMNShape id="shape-8d5f52a3-a6a2-4f64-9efb-e9837679722e" bpmnElement="sid-0347a044-9d2e-465b-a449-eb6699044ae4">
        <omgdc:Bounds x="-235.35788" y="16.2278" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-486bc80b-61bf-464f-be0f-a586c65eb86e" bpmnElement="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe">
        <omgdc:Bounds x="-217.49924" y="92.053925" width="221.21466" height="121.94145"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-f95a940b-f150-49f8-9d86-09923329f6d0" bpmnElement="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa">
        <omgdc:Bounds x="-157.19922" y="114.25392" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-08ea584c-b113-4d02-9d65-156a6fb35a50" bpmnElement="sid-35fbe381-270f-4ade-bf1b-1e32c289f946">
        <omgdc:Bounds x="-35.8492" y="139.25392" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-993acd65-bf4f-4337-96d4-eb6c5ce1fdab" bpmnElement="sid-36a022c4-ff28-44f7-8694-b23cf7592b68">
        <omgdi:waypoint x="-57.19922" y="154.25392"/>
        <omgdi:waypoint x="-35.8492" y="154.25392"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-07af35b3-f623-4fdd-99ae-675c6c7894e6" bpmnElement="sid-2efe3807-4285-416c-a2b7-c3827ec433d2">
        <omgdc:Bounds x="105.030174" y="16.227798" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-bae0f412-1c38-4baf-a8d8-a4740dc0c63e" bpmnElement="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a">
        <omgdc:Bounds x="-156.8919" y="-8.7722" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-b07f91be-b837-448d-a8a7-0892ac5b39a2" bpmnElement="sid-3747e8f1-b5c6-4b83-b8af-c74038303170">
        <omgdi:waypoint x="-56.891907" y="31.2278"/>
        <omgdi:waypoint x="-23.466818" y="31.227797"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-f2b44140-d7d8-4110-8001-8eb61b3ae601" bpmnElement="sid-9f66c2ee-3281-486e-9aea-e27f29dad682">
        <omgdc:Bounds x="-207.4492" y="139.25392" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-26b2554a-e5f0-4b44-a70a-00b3ff5812be" bpmnElement="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2">
        <omgdi:waypoint x="-177.4492" y="154.25392"/>
        <omgdi:waypoint x="-157.19922" y="154.25392"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-ea9c91b4-9a2b-4e63-bba6-4f36d68c4f81" bpmnElement="sid-b3c67896-5be8-4c59-b046-4c4affb36555">
        <omgdi:waypoint x="-205.35788" y="31.2278"/>
        <omgdi:waypoint x="-156.8919" y="31.2278"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-f8f20ee5-036e-492f-b7af-33dde9d12290" bpmnElement="sid-2909cd9a-c18a-429b-be89-4543b6524bbc">
        <omgdc:Bounds x="-23.466816" y="-8.772202" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-004bd7a2-8a83-4bb1-a732-2afcd4bf131e" bpmnElement="sid-bff0ca04-cd48-4aa9-8405-66e63124e59b">
        <omgdi:waypoint x="76.53319" y="31.227798"/>
        <omgdi:waypoint x="105.030174" y="31.227798"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
测试流程
java">@Test
public void deployAndStartProcessByErrorStart() {
    // 部署流程
    Deployment deploy = repositoryService.createDeployment()
            .addClasspathResource("processes/error-start.bpmn20.xml")
            .deploy();
    System.out.println("deploy = " + deploy);

    // 启动流程
    String processDefinitionKey = "error-start";
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, processDefinitionKey + ":100001");
    System.out.println("processInstance = " + processInstance);
}
流程执行步骤
// 1.部署并启动流程
// 2.触发服务任务,服务任务监听器抛出异常,错误码errorCode
// 3.子流程接收到错误码为errorCode,触发错误开始事件
// 4.触发子流程服务任务
// 5.结束流程

边界与结束事件

流程图设计一个子流程,然后子流程里面有一个错误结束事件。外面的错误捕获边界任务就会捕获异常。捕获了异常后由于是错误边界先去捕获异常,所以捕获错误事件分支会先执行,然后结束。正常结束事件节点所在的分支不会执行。

开始 - 子流程开始 - 排他网关 - 错误结束事件 - 错误边界事件 - 结束流程
在这里插入图片描述

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">
  <!-- 定义错误 -->
  <error id="error1" name="errorCode1" errorCode="123456"/>
  <process id="error-boundary-end" name="错误边界与结束事件" isExecutable="true">
    <documentation>错误边界与结束事件</documentation>
    <!-- 开始事件 -->
    <startEvent id="sid-0347a044-9d2e-465b-a449-eb6699044ae4" name="开始事件"/>
    <!-- 子流程 -->
    <subProcess id="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" activiti:exclusive="true">
      <!-- 子流程开始事件 -->
      <startEvent id="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" name="子流程开始事件"/>
      <!-- 子流程服务任务抛出异常 -->
      <!-- 子流程结束事件 -->
      <sequenceFlow id="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2" sourceRef="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" targetRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa"/>
      <!-- 保存信息任务 -->
      <userTask id="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" name="保存信息任务" activiti:assignee="${assignee}">
        <extensionElements>
          <activiti:taskListener event="create" delegateExpression="${myUserTaskListener}"/>
        </extensionElements>
      </userTask>
      <!-- 排他网关 -->
      <exclusiveGateway id="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734"/>
      <!-- 保存成功 -->
      <endEvent id="sid-216515ff-91cb-4ec3-8d1e-c36a128f2dbf" name="保存成功"/>
      <!-- 错误结束事件 -->
      <endEvent id="sid-1600e3d8-61f9-428f-82c8-c048ef84c774" name="错误结束事件">
        <!-- 引用错误码 -->
        <errorEventDefinition errorRef="error1"/>
      </endEvent>
      <sequenceFlow id="sid-bfbfcc21-b6db-4275-9726-0560d0c397dd" sourceRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" targetRef="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734"/>
      <sequenceFlow id="sid-82b537d9-8377-4d7a-a3e1-7d204afe45dd" sourceRef="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734" targetRef="sid-216515ff-91cb-4ec3-8d1e-c36a128f2dbf" name="保存成功">
        <conditionExpression xsi:type="tFormalExpression"><![CDATA[${save}]]></conditionExpression>
      </sequenceFlow>
      <sequenceFlow id="sid-1905e28e-c5ea-4827-913e-c3c4853056db" sourceRef="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734" targetRef="sid-1600e3d8-61f9-428f-82c8-c048ef84c774" name="保存失败">
        <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!save}]]></conditionExpression>
      </sequenceFlow>
    </subProcess>
    <!-- 错误边界事件 -->
    <boundaryEvent id="sid-ddef4f3c-3395-42e5-baa4-1122338da889" attachedToRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" cancelActivity="false" name="错误边界事件">
      <!-- 引用错误码 -->
      <errorEventDefinition errorRef="error1"/>
    </boundaryEvent>
    <sequenceFlow id="sid-792f09fd-d9f8-44a3-abe6-c01a42f5f1d8" sourceRef="sid-ddef4f3c-3395-42e5-baa4-1122338da889" targetRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe"/>
    <!-- 服务任务 -->
    <serviceTask id="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" activiti:exclusive="true" name="服务任务" activiti:delegateExpression="${myServiceTaskListener}"/>
    <!-- 结束事件1 -->
    <endEvent id="sid-2efe3807-4285-416c-a2b7-c3827ec433d2" name="结束事件1"/>
    <sequenceFlow id="sid-3747e8f1-b5c6-4b83-b8af-c74038303170" sourceRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" targetRef="sid-2efe3807-4285-416c-a2b7-c3827ec433d2"/>
    <sequenceFlow id="sid-e12fb2e5-97ad-458a-9954-8531754b6bb1" sourceRef="sid-0347a044-9d2e-465b-a449-eb6699044ae4" targetRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe"/>
    <sequenceFlow id="sid-1296aafe-77e0-46ed-be02-40e77e483512" sourceRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" targetRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_error">
    <bpmndi:BPMNPlane bpmnElement="error-boundary-end" id="BPMNPlane_error">
      <bpmndi:BPMNShape id="shape-8d5f52a3-a6a2-4f64-9efb-e9837679722e" bpmnElement="sid-0347a044-9d2e-465b-a449-eb6699044ae4">
        <omgdc:Bounds x="-366.3918" y="140.0239" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-486bc80b-61bf-464f-be0f-a586c65eb86e" bpmnElement="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe">
        <omgdc:Bounds x="-289.65228" y="96.042305" width="321.05652" height="117.96317"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-f95a940b-f150-49f8-9d86-09923329f6d0" bpmnElement="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa">
        <omgdc:Bounds x="-228.40327" y="117.33385" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-07af35b3-f623-4fdd-99ae-675c6c7894e6" bpmnElement="sid-2efe3807-4285-416c-a2b7-c3827ec433d2">
        <omgdc:Bounds x="225.4221" y="139.25394" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-bae0f412-1c38-4baf-a8d8-a4740dc0c63e" bpmnElement="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a">
        <omgdc:Bounds x="79.65822" y="114.25394" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-b07f91be-b837-448d-a8a7-0892ac5b39a2" bpmnElement="sid-3747e8f1-b5c6-4b83-b8af-c74038303170">
        <omgdi:waypoint x="179.65819" y="154.25394"/>
        <omgdi:waypoint x="225.4221" y="154.25394"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-f2b44140-d7d8-4110-8001-8eb61b3ae601" bpmnElement="sid-9f66c2ee-3281-486e-9aea-e27f29dad682">
        <omgdc:Bounds x="-280.5647" y="142.33385" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-26b2554a-e5f0-4b44-a70a-00b3ff5812be" bpmnElement="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2">
        <omgdi:waypoint x="-250.5647" y="157.33385"/>
        <omgdi:waypoint x="-228.40327" y="157.33385"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-61a3490a-54fd-4ab1-a770-b76eb42652a1" bpmnElement="sid-e12fb2e5-97ad-458a-9954-8531754b6bb1">
        <omgdi:waypoint x="-336.3918" y="155.0239"/>
        <omgdi:waypoint x="-289.65228" y="155.02391"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-5d002380-d175-4884-815c-14fc1759d1a4" bpmnElement="sid-1296aafe-77e0-46ed-be02-40e77e483512">
        <omgdi:waypoint x="31.404236" y="155.0239"/>
        <omgdi:waypoint x="79.65822" y="154.25394"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-522ed462-bae8-444e-a8b9-477fda868b8c" bpmnElement="sid-ddef4f3c-3395-42e5-baa4-1122338da889">
        <omgdc:Bounds x="-116.11634" y="197.29118" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-8a740a35-cad6-4347-8ef6-1a46a2ee8268" bpmnElement="sid-792f09fd-d9f8-44a3-abe6-c01a42f5f1d8">
        <omgdi:waypoint x="-101.11635" y="227.29118"/>
        <omgdi:waypoint x="-101.11634" y="265.13498"/>
        <omgdi:waypoint x="-209.38815" y="265.13498"/>
        <omgdi:waypoint x="-209.38815" y="214.0055"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-df93b38f-f194-4162-a655-ec4ee7862752" bpmnElement="sid-1600e3d8-61f9-428f-82c8-c048ef84c774">
        <omgdc:Bounds x="-34.357986" y="176.21335" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-6e2c6138-5753-4047-b044-9ce53ef91f30" bpmnElement="sid-bfbfcc21-b6db-4275-9726-0560d0c397dd">
        <omgdi:waypoint x="-128.40327" y="157.33385"/>
        <omgdi:waypoint x="-102.3249" y="157.33388"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-ed1e9d9e-02f7-445b-be90-8e805e4b99e2" bpmnElement="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734">
        <omgdc:Bounds x="-102.32489" y="137.33386" width="40.0" height="40.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-92c333a1-02bf-4e06-a7a6-6efabb4c2c07" bpmnElement="sid-216515ff-91cb-4ec3-8d1e-c36a128f2dbf">
        <omgdc:Bounds x="-34.357986" y="107.18444" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-e6ac924d-c7f7-428e-8f2c-189e005b8682" bpmnElement="sid-82b537d9-8377-4d7a-a3e1-7d204afe45dd">
        <omgdi:waypoint x="-82.32488" y="137.33385"/>
        <omgdi:waypoint x="-34.357986" y="122.18445"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-efeec91d-d6e8-4106-baa0-f5c292ce0e78" bpmnElement="sid-1905e28e-c5ea-4827-913e-c3c4853056db">
        <omgdi:waypoint x="-82.32489" y="177.33386"/>
        <omgdi:waypoint x="-34.357983" y="191.21335"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
自定义错误监听器
java">@Component
public class MyThrowErrorDelegateListener implements JavaDelegate, Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public void execute(DelegateExecution execution) {
        System.out.println("《================服务任务错误监听器================》");
        System.out.println("当前时间:" + DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN));
        System.out.println("delegateTask.getProcessInstanceId() = " + execution.getProcessInstanceId());
        System.out.println("delegateTask.getProcessInstanceBusinessKey() = " + execution.getProcessInstanceBusinessKey());
        System.out.println("delegateTask.getEventName() = " + execution.getEventName());
        System.out.println("execution.getCurrentFlowElement().getName() = " + execution.getCurrentFlowElement().getName());
        // 抛出异常
        String errorCode = "123456";
        System.out.println("抛出错误码:" + errorCode);
        throw new BpmnError(errorCode);
    }
}
测试流程
java">@Test
public void deployAndStartProcessByErrorBoundaryAndEnd() {
    // 部署流程
    Deployment deploy = repositoryService.createDeployment()
            .addClasspathResource("processes/error-boundary-end.bpmn20.xml")
            .deploy();
    System.out.println("deploy = " + deploy);

    // 启动流程
    Map<String, Object> variables = new HashMap<>();
    variables.put("assignee", "user123456");
    String processDefinitionKey = "error-boundary-end";
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, processDefinitionKey + ":1000011", variables);
    System.out.println("processInstance = " + processInstance);
}

@Test
public void completeTaskForErrorBoundaryAndEnd() {
    // 查询任务
    Task task = taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).taskAssignee("user123456").singleResult();
    System.out.println("task = " + task);
    // 完成任务
    Map<String, Object> hashMap = new HashMap<>();
    hashMap.put("save", true);
    taskService.complete(task.getId(), hashMap, true);
}
流程执行步骤
// 1.部署并启动流程
// 2.当前任务保存用户任务
// 3.完成用户任务save=false
// 4.触发错误结束事件,边界事件捕获到errorCode=123456,流程循环保存用户任务(如果一直是false)
// 5.当完成用户任务save=true
// 6.子流程结束
// 7.触发服务任务
// 8.结束流程

http://www.niftyadmin.cn/n/5231304.html

相关文章

单片机实现数码管动态显示

动态显示的特点是将所有位数码管的段选线并联在一起&#xff0c;由位选线控制是哪一位数码管有效。这样一来&#xff0c;就没有必要每一位数码管配一个锁存器&#xff0c;从而大大地简化了硬件电路。选亮数码管采用动态扫描显示。所谓动态扫描显示即轮流向各位数码管送出字形码…

登录校验——JWT(JSON Web Token)介绍

目录 一、前后端分析二、JWT在前后端的联系1. 前端实现2. 后端实现 三、JWT在登录中的作用和优缺点1. 作用2. 优缺点 JWT&#xff08;JSON Web Token&#xff09;是一种在Java前后端分离项目中实现登录功能的常用方式。本文将对前后端的分析&#xff0c;JWT在前后端的联系以及其…

​iOS Class Guard github用法、工作原理和安装详解及使用经验总结

iOS Class Guard是一个用于OC类、协议、属性和方法名混淆的命令行工具。它是class-dump的扩展。这个工具会生成一个symbol table&#xff0c;这个table在编译期间会包含进工程中。iOS-Class-Guard能有效的隐藏绝大多数的类、协议、方法、属性和 实例变量 名。iOS-Class-Guard不…

基于RV1126的边缘AI计算盒子,新零售、智慧城管、智能安防、智慧课堂

边缘计算盒子 瑞芯微rv1126 | 2.0TOPS INT8/INT16 ● 集成了NPU&#xff0c;算力高达2.0TOPsINT8/INT16。 ● 支持H.264/H.265/MJPEG视频编解码&#xff1b;支持多级别视频质量配置及编码复杂度设置。 ● 编解码性能 3840 x 216030 fps 1080p30 fps encoding 3840 x 21603…

香港服务器时间不准,差8小时

解决方案 1、timedatectl查看系统时间 2、查看系统时区 ls /usr/share/zoneinfo 3、删除当前系统所处时区 rm /etc/localtime 4、创建软链接&#xff0c;以替换当前的时区信息 ln -s /usr/share/zoneinfo/Universal /etc/localtime

论文阅读_AI生成检测_Ghostbuster

英文名称: Ghostbuster: Detecting Text Ghostwritten by Large Language Models 中文名称: 捉鬼人&#xff1a;检测大语言模型生成的文本 文章: http://arxiv.org/abs/2305.15047 代码: https://github.com/vivek3141/ghostbuster 作者: Vivek Verma&#xff0c;Eve Fleisig&a…

centos 7 下运行route -n,报命令不存在

centos 7 下运行route -n 报命令不存在。 route -n -bash: route: command not found需要安装&#xff1a;net-tools。 Net-tools 是一套网络工具集&#xff0c;用于在 Linux 系统中进行网络管理和配置。它包含了一系列命令行工具&#xff0c;用于查看和操作网络接口、路由表…

高效、精准、安全:无人机自主巡检助推电力应用大升级

在江苏某变电站运检中心&#xff0c;工作人员启动了无人机自主巡检平台&#xff0c;开始无人机自主巡检任务。巡检管控中心的大屏实时显示无人机自主巡检的飞行轨迹和相关信息&#xff0c;全方位监控设备的安全状态。 一、复亚智能助推变电站数字化转型 江苏某变电站作为连接多…