在讲发布流程之前,我先普及一下activiti6的七大接口
RepositoryService:提供一系列管理流程部署和流程定义的API。
RuntimeService:在流程运行时对流程实例进行管理与控制。
TaskService:对流程任务进行管理,例如任务提醒、任务完成和创建任务等。
HistoryService:对流程的历史数据进行操作,包括查询、删除这些历史数据。
IdentityService:提供对流程角色数据进行管理的API,这些角色数据包括用户组、用户及它们之间的关系。
ManagementService:提供对流程引擎进行管理和维护的服务。
FormService:表单服务。
也就是说想要进行所有的流程操作,都要通过流程引擎 ProcessEngine,而我之前自动建28张表的方法不太好在各个方法中获取流程引擎,因此,我又换了一种方式建表,首先我需要删除28张表
DROP TABLE act_evt_log;
DROP TABLE act_ge_property;
DROP TABLE act_hi_actinst;
DROP TABLE act_hi_attachment;
DROP TABLE act_hi_comment;
DROP TABLE act_hi_detail;
DROP TABLE act_hi_identitylink;
DROP TABLE act_hi_procinst;
DROP TABLE act_hi_taskinst;
DROP TABLE act_hi_varinst;
DROP TABLE act_id_info;
DROP TABLE act_id_membership;
DROP TABLE act_id_user;
DROP TABLE act_procdef_info;
DROP TABLE act_re_model;
DROP TABLE act_ru_deadletter_job;
DROP TABLE act_ru_event_subscr;
DROP TABLE act_ru_identitylink;
DROP TABLE act_ru_job;
DROP TABLE act_ru_suspended_job;
DROP TABLE act_ru_task;
DROP TABLE act_ru_timer_job;
DROP TABLE act_ru_variable;
DROP TABLE act_ge_bytearray;
DROP TABLE act_id_group;
DROP TABLE act_re_deployment;
DROP TABLE act_ru_execution;
DROP TABLE act_re_procdef;
在spring目录下建activiti.cfg.xml
文件内容如下
<?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.xsd">
<!-- Activiti的引擎配置管理器 -->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!-- 指定数据源 -->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
自动建表
@Test
public void createTable() {
ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine engine = cfg.buildProcessEngine();
}
通过此种方式建表,便可以使用ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();获取流程引擎了
然后新建bpmn文件,流程图怎么画自行百度,需要下载插件,我的流程图如下
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1605510641081" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="myProcess_1" isClosed="false" isExecutable="true" processType="None">
<startEvent id="_2" name="开始"/>
<userTask activiti:exclusive="true" id="_3" name="经理审批"/>
<userTask activiti:exclusive="true" id="_4" name="领导审批"/>
<endEvent id="_5" name="结束"/>
<sequenceFlow id="_6" sourceRef="_2" targetRef="_3"/>
<sequenceFlow id="_7" sourceRef="_3" targetRef="_4"/>
<sequenceFlow id="_8" sourceRef="_4" targetRef="_5"/>
</process>
<bpmndi:BPMNDiagram documentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
<bpmndi:BPMNPlane bpmnElement="myProcess_1">
<bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
<omgdc:Bounds height="32.0" width="32.0" x="525.0" y="5.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
<omgdc:Bounds height="55.0" width="85.0" x="505.0" y="95.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
<omgdc:Bounds height="55.0" width="85.0" x="505.0" y="200.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
<omgdc:Bounds height="32.0" width="32.0" x="525.0" y="305.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6" sourceElement="_2" targetElement="_3">
<omgdi:waypoint x="541.0" y="37.0"/>
<omgdi:waypoint x="541.0" y="95.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7" sourceElement="_3" targetElement="_4">
<omgdi:waypoint x="547.5" y="150.0"/>
<omgdi:waypoint x="547.5" y="200.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_4" targetElement="_5">
<omgdi:waypoint x="541.0" y="255.0"/>
<omgdi:waypoint x="541.0" y="305.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
接下来就是发布流程了
//发布流程
@Test
public void deployProcess(){
ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
DeploymentBuilder builder = repositoryService.createDeployment();
builder.addClasspathResource("process/forRest.bpmn");
Deployment deployment= builder.deploy();
System.out.println("部署ID:" + deployment.getId());
System.out.println("部署名称:" + deployment.getName());
}
结果如下,对应的表为act_re_deployment