Flowable BPMN2.0 Workflow Engine Tutorial: From Basics to Practical Implementation
This article provides a comprehensive guide to Flowable, a Java-based BPMN 2.0 workflow engine, covering its concepts, BPMN elements, installation, configuration, code examples, and database schema, enabling developers to design and implement employee leave approval processes.
1. Introduction to Workflow
Workflow abstracts business steps and rules into a model that can be executed by a computer, reducing complex code logic for approval processes.
1.1 Why Use Workflow
Traditional field‑based state handling becomes cumbersome for multi‑stage approvals; a workflow engine decouples business logic from implementation.
1.2 What Is a Workflow
A workflow is a generalized state machine that models business processes using a dedicated language such as BPMN.
2. BPMN 2.0 Specification
BPMN 2.0 provides a standard, human‑readable and machine‑parsable notation for modeling processes.
2.2 BPMN Elements
Gateways : Exclusive, Parallel, Inclusive – control flow branching.
Tasks : User Task, Service Task, Receive Task, Call Activity – represent work units.
3. Flowable Overview
Flowable is a lightweight Java implementation of the BPMN 2.0 engine, capable of embedding in Spring Boot applications or running as a standalone server.
3.2 Flowable vs. Activiti
Flowable forks from Activiti‑6.0.0.Beta4 and fixes many bugs, allowing zero‑cost migration.
4. Practical Flowable Project
Steps to build an employee leave request workflow:
Create a flowable-ui Spring Boot project to design the process diagram.
Export the diagram as an XML file and place it under resources/processes in a second Spring Boot project.
Configure application.yml (server port, datasource, Flowable settings).
Include required Maven dependencies (spring‑boot‑starter, flowable‑spring‑boot‑starter‑ui‑idm, modeler, JPA, MySQL).
Key XML snippets:
<process id="leave" name="Company Employee Leave Process" isExecutable="true">
<startEvent id="startEvent1" name="Start"/>
<userTask id="apply" name="Leave Application" flowable:assignee="${studentUser}"/>
<userTask id="teacherPass" name="Leader Approval" flowable:candidateGroups="a"/>
<exclusiveGateway id="judgeTask" name="Is >2 days?"/>
<userTask id="principalPass" name="Boss Approval" flowable:candidateGroups="b"/>
<endEvent id="end" name="End"/>
...
</process>Sample Java test code (SpringBootTest) demonstrates how to start a process, query tasks, complete approvals, and retrieve historic activity data:
@SpringBootTest
class JavaSkillPointApplicationTests {
@Autowired RuntimeService runtimeService;
@Autowired TaskService taskService;
@Autowired HistoryService historyService;
@Test
void startLeave() {
Map
vars = new HashMap<>();
vars.put("day",5);
vars.put("studentUser","XiaoMing");
ProcessInstance pi = runtimeService.startProcessInstanceByKey("leave",vars);
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
taskService.complete(task.getId());
}
// Additional tests for leader, boss approvals and history queries
}4.4 Flowable Database Tables
Flowable tables are prefixed with ACT_ and grouped by purpose:
ACT_RE_* – repository (static definitions, resources).
ACT_RU_* – runtime (variables, active tasks, jobs).
ACT_HI_* – history (completed instances, tasks).
ACT_ID_* – identity (users, groups).
ACT_GE_* – generic data.
Diagrams of the table structures are provided in the original article.
The article concludes with a reminder that the content is intended for technical discussion and not for advertising.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.