来源:http://www.bug315.com/article/164.htm
Activiti无指定开始事件指不为开始事件指定任何的触发条件的事件。下面将通过一个实例来学习什么是无指定开始事件。
startEvent(无指定开始事件图标)
流程图:
startEvent
流程启动后进入“任务01”(调用complete方法来完成该任务),然后结束流程。
流程定义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: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="startEventTest01" name="开始事件测试01" isExecutable="true">
<startEvent id="start"></startEvent>
<userTask id="task01" name="任务01"></userTask>
<endEvent id="end"></endEvent>
<sequenceFlow id="sid-B96A1813-6837-4845-8167-3ACA1A3B3D20" sourceRef="start" targetRef="task01"></sequenceFlow>
<sequenceFlow id="sid-35F14E43-5255-4FCC-8962-209578CDE088" sourceRef="task01" targetRef="end"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_startEventTest01">
<bpmndi:BPMNPlane bpmnElement="startEventTest01" id="BPMNPlane_startEventTest01">
<bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
<omgdc:Bounds height="30.0" width="30.0" x="116.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="task01" id="BPMNShape_task01">
<omgdc:Bounds height="80.0" width="100.0" x="191.0" y="125.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
<omgdc:Bounds height="28.0" width="28.0" x="336.0" y="151.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-35F14E43-5255-4FCC-8962-209578CDE088" id="BPMNEdge_sid-35F14E43-5255-4FCC-8962-209578CDE088">
<omgdi:waypoint x="291.0" y="165.0"></omgdi:waypoint>
<omgdi:waypoint x="336.0" y="165.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-B96A1813-6837-4845-8167-3ACA1A3B3D20" id="BPMNEdge_sid-B96A1813-6837-4845-8167-3ACA1A3B3D20">
<omgdi:waypoint x="146.0" y="165.0"></omgdi:waypoint>
<omgdi:waypoint x="191.0" y="165.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
客户端测试代码:
package com.bug315.event;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
/**
* 开始事件测试
* @author Administrator
*
*/
public class StartEventTest01 {
public static void main(String[] args) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = repositoryService.createDeployment().addClasspathResource("bpmn/startEventTest01.bpmn20.xml").deploy();
System.out.println("deployment Id = " + deployment.getId());
System.out.println("deployment Name = " + deployment.getName());
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startEventTest01");
System.out.println("processInstance Id = " + processInstance.getId());
System.out.println("processInstance BusinessKey = " + processInstance.getBusinessKey());
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().singleResult();
System.out.println("task Id = " + task.getId());
System.out.println("task Name = " + task.getName());
taskService.complete(task.getId());
System.out.println("task完成");
task = taskService.createTaskQuery().singleResult();
System.out.println("task = " + task);
}
}
Activiti配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="aaaaaa" />
<property name="jobExecutorActivate" value="true" />
<property name="databaseType" value="mysql"/>
<property name="databaseSchemaUpdate" value="true" />
<property name="history" value="full"/>
</bean>
</beans>
注意事项:
1、流程引擎并不知道流程将在什么时候开始,如果要启动流程,必须使用startProcessBy***方法。
2、子流程中总会有一个无指定开始事件,即使将开始事件强制定义为其他开始事件,其也会被当作无指定开始事件。因为流程到达子流程时,就意味着子流程需要启动,而且并不需要其他启动条件。