springboot整合activiti6.0
新建springboot项目,
添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>6.0.0</version> </dependency>
在启动类上添加 exclude = SecurityAutoConfiguration.class,是 org.activiti.spring.boot.SecurityAutoConfiguration包中的

在resources中创建processes文件夹,里面放bpmn文件,里面的bpmn会自动部署

配置文件进行配置

启动项目,会自动在数据库创建28张表。
idea的bpmn插件不好用,所以选择在eclipse编辑bpmn文件,完成后复制到idea

<?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/test"> <process id="vacation" name="vacation request" isExecutable="true"> <startEvent id="startevent1" name="Start"></startEvent> <userTask id="usertask1" name="User Task" activiti:assignee="manager"> <extensionElements> <activiti:formProperty id="vacationApprove" name="approveVacation" type="enum" required="true"> <activiti:value id="true" name="Approve"></activiti:value> <activiti:value id="false" name="Reject"></activiti:value> </activiti:formProperty> </extensionElements> </userTask> <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway> <userTask id="usertask2" name="User Task" activiti:assignee="zbc"></userTask> <userTask id="usertask3" name="User Task" activiti:assignee="libai"></userTask> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow> <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow> <sequenceFlow id="flow3" sourceRef="exclusivegateway1" targetRef="usertask3" skipExpression="${vacationApprove=='false'}"></sequenceFlow> <sequenceFlow id="flow4" sourceRef="exclusivegateway1" targetRef="usertask2" skipExpression="${vacationApprove=='true'}"></sequenceFlow> <sequenceFlow id="flow5" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow> <sequenceFlow id="flow6" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_vacation"> <bpmndi:BPMNPlane bpmnElement="vacation" id="BPMNPlane_vacation"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="80.0" y="240.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"> <omgdc:Bounds height="55.0" width="105.0" x="190.0" y="230.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"> <omgdc:Bounds height="40.0" width="40.0" x="380.0" y="240.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"> <omgdc:Bounds height="55.0" width="105.0" x="530.0" y="170.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"> <omgdc:Bounds height="55.0" width="105.0" x="530.0" y="320.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="740.0" y="256.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="115.0" y="257.0"></omgdi:waypoint> <omgdi:waypoint x="190.0" y="257.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="295.0" y="257.0"></omgdi:waypoint> <omgdi:waypoint x="380.0" y="260.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> <omgdi:waypoint x="400.0" y="280.0"></omgdi:waypoint> <omgdi:waypoint x="400.0" y="347.0"></omgdi:waypoint> <omgdi:waypoint x="530.0" y="347.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"> <omgdi:waypoint x="400.0" y="240.0"></omgdi:waypoint> <omgdi:waypoint x="400.0" y="197.0"></omgdi:waypoint> <omgdi:waypoint x="530.0" y="197.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"> <omgdi:waypoint x="582.0" y="225.0"></omgdi:waypoint> <omgdi:waypoint x="757.0" y="256.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"> <omgdi:waypoint x="582.0" y="320.0"></omgdi:waypoint> <omgdi:waypoint x="757.0" y="291.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
简单的仿请假流程,进行审批,网关做判断,通过执行一个操作,不通过执行另一个操作。

直接注入即可,因为是自动部署,所以直接通过key启动一个流程。
runtimeService.startProcessInstanceByKey("vacation");
完成任务
List<Task> list = taskService.createTaskQuery().taskCandidateOrAssigned("manager").list();//查询分配给manager的流程任务
Task task = list.get(0);
System.out.println(task.toString());
Map<String, Object> taskVariables = new HashMap<String, Object>();//参数
taskVariables.put("vacationApprove",false);//通过还是不通过
taskService.complete(task.getId(),taskVariables);//完成任务

浙公网安备 33010602011771号