Flowable开源/企业版:Spring Boot部署BPMN后如何查看流程流转?
实现Spring Boot中Flowable流程流转查看功能的方案
1. 直接集成Flowable Admin模块到Spring Boot项目
不想从零开发的话,直接把官方Flowable Admin的模块集成进来,就能复用现成的UI功能:
- 在Maven的
pom.xml中添加依赖:<dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-admin</artifactId> <version>你的Flowable版本号</version> </dependency> - 在
application.yml里配置引擎连接信息(如果是同项目的本地引擎,直接用本地地址即可):flowable: admin: app: engine-rest-url: http://localhost:8080/flowable-rest - 启动项目后,访问
/admin路径就能进入和官方Flowable Admin完全一致的界面,直接查看流程实例、当前任务、流转历史等信息。
2. 调用Flowable REST API自定义前端界面
如果不想用官方UI,也可以自己写前端页面,通过Flowable提供的REST接口获取流程数据:
- 先引入Flowable REST Starter依赖:
<dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-rest</artifactId> <version>你的Flowable版本号</version> </dependency> - 常用的核心接口:
- 获取所有运行中流程实例:
GET /flowable-rest/service/runtime/process-instances - 获取指定流程实例的完整流转历史:
GET /flowable-rest/service/history/historic-process-instances/{processInstanceId}/activity-instances - 获取流程实例当前所处的活动节点:
GET /flowable-rest/service/runtime/process-instances/{processInstanceId}/activities
- 获取所有运行中流程实例:
- 这些接口返回的JSON数据包含了节点名称、执行时间、任务状态等信息,你可以根据需求自己渲染流程图或数据列表。
3. 直接调用Flowable Java API查询数据
如果不需要对外提供REST接口,也可以在Spring Boot业务代码里直接调用Flowable的Java API查询流程信息:
- 先注入Flowable的核心服务类:
@Autowired private RuntimeService runtimeService; @Autowired private HistoryService historyService; @Autowired private RepositoryService repositoryService; - 查询流程实例当前的执行节点:
// 根据流程实例ID获取当前执行的活动节点 List<Execution> executions = runtimeService.createExecutionQuery() .processInstanceId(processInstanceId) .list(); for (Execution execution : executions) { String activityId = execution.getActivityId(); // 从流程定义中获取节点的详细信息 BpmnModel bpmnModel = repositoryService.getBpmnModel(execution.getProcessDefinitionId()); FlowElement flowElement = bpmnModel.getMainProcess().getFlowElement(activityId); if (flowElement instanceof UserTask) { UserTask userTask = (UserTask) flowElement; System.out.println("当前节点:" + userTask.getName()); } } - 查询流程的完整流转历史:
// 获取流程实例的所有历史活动记录 List<HistoricActivityInstance> historicActivities = historyService.createHistoricActivityInstanceQuery() .processInstanceId(processInstanceId) .orderByHistoricActivityInstanceStartTime() .asc() .list(); for (HistoricActivityInstance activity : historicActivities) { System.out.println("流转节点:" + activity.getActivityName() + ",执行时间:" + activity.getStartTime()); } - 拿到这些数据后,可以自己封装成接口返回给前端,或者直接在后端控制台查看。
内容的提问来源于stack exchange,提问作者Srideep Bhattacharjee
相关产品推荐
相关产品推荐

