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);//完成任务
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律