Logo Dark
Get In Touch

Flowable Spring Boot Tutorial: Build a BPMN 2.0 Workflow in Java

/
AI

Flowable is an open-source Java workflow engine that runs BPMN 2.0 process files inside your Spring Boot application. You add one starter dependency, drop a .bpmn20.xml file into src/main/resources/processes/, and Flowable creates its tables, deploys the process and tracks every running instance in your own database.

Picture a leave approval or an expense claim. Version one is simple: an employee submits, a manager approves, the status column flips to APPROVED. Then the requests start arriving. Claims above $500 need a second approver. A manager who ignores a request for two days should get a reminder. A payout that fails halfway has to resume where it stopped. Six months later the logic lives in status flags, nested if blocks and three cron jobs nobody wants to touch.

This guide shows the alternative: model the process once in BPMN 2.0, and let Flowable run it.

Key Takeaways

  • Flowable is an Apache 2.0, embeddable Java workflow engine; Flowable 7 targets Java 17 and Spring Boot 3.
  • One starter dependency gives you auto-configured
  • BPMN 2.0 files are executable XML, so the diagram and the running process are the same artifact.
  • Process state lives in your database and survives restarts.

What Is BPMN 2.0, and Why Does It Matter for Developers?

BPMN 2.0 (Business Process Model and Notation) is an OMG standard, published in 2011, that defines both a diagram notation and an XML format for business processes. The XML is the part developers care about: a workflow engine can execute the same file an analyst drew, so the picture and the code stay in sync.

Earlier flowchart notations were drawings. A developer read the boxes and arrows, then rewrote them by hand as Java, and the two drifted apart from the first release. BPMN 2.0 closes that gap. Each shape maps to an XML element with defined execution rules, and any compliant engine knows how to run it.

How Do BPMN 2.0 and Flowable Work Together?

Think of BPMN 2.0 as the blueprint and Flowable as the crew that builds from it.

  • The BPMN 2.0 file defines the steps, the decisions, the order and who does what.
  • The Flowable engine reads that file, creates a process instance per request, records where each instance stands, calls your code at automated steps and waits at human ones.

Which BPMN 2.0 Elements Do You Need First?

Five elements cover most business workflows. Learn these and you can read the majority of real-world BPMN 2.0 examples.

ElementShapeWhat it does in Flowable
Start / End eventCircleMarks where an instance begins and finishes
User taskRounded box with a person iconPauses the instance until someone claims and completes it
Service taskRounded box with a gear iconCalls a Spring bean or Java class automatically
Exclusive gatewayDiamond with an XPicks exactly one outgoing path based on data, like an if/else
Timer boundary eventClock on a task's edgeFires after a duration or date while the task is still open

Parallel gateways, message events and sub-processes come later. You won't need them for a first approval flow.

What Is the Flowable Engine?

Flowable is a lightweight Java BPM engine that started in 2016 as a fork of Activiti, led by Activiti's own core developers, and ships under the Apache 2.0 licence. Alongside the BPMN engine it includes CMMN for case management and DMN for decision tables, all usable from the same Spring Boot starter.

Its job is lifecycle management. Flowable starts process instances, persists their state after every step, assigns user tasks to people or groups, fires timers, retries failed async jobs and writes a history record when each step finishes. You stop writing the plumbing that tracks "which step is request 4127 on, and who owns it now?"

The practical test for whether you need an engine: count the states your entity can be in and the transitions between them. Once a status column has more than five or six values and some transitions depend on time or on a person, you're maintaining a hand-built workflow engine already. It just doesn't have history, retries or a diagram.

Why Use Flowable in a Spring Boot Application?

Spring Boot is built for short request/response work: an HTTP call comes in, a transaction commits, the thread returns in milliseconds. Business processes run for hours, days or weeks, and they wait on people and external systems. Flowable bridges that gap by saving each instance's position to the database between steps.

What that buys you:

  • Fewer status flags. The BPMN 2.0 definition holds the routing rules, so your entities stop carrying
  • State that survives restarts. Every wait state is a committed row. Redeploy the app mid-approval and the instance carries on.
  • Human tasks out of the box. Task queries, candidate groups, claim and complete are API calls on
  • Timers without cron. Reminders and escalations are timer events in the model, run by Flowable's async executor.
  • An audit trail. The

Is it worth it for a two-step flow that will never change? Probably not. Flowable earns its place once the process has branches, waits or people in it, which is where most approval and onboarding logic ends up.

If your team is planning a larger Java build around workflows like these, our guide to enterprise application development covers how we scope that kind of system.

How Does Flowable Work Inside Spring Boot?

The flowable-spring-boot-starter auto-configures the engine against your existing Spring DataSource and transaction manager. On startup it creates or updates its tables, scans classpath:processes/ for *.bpmn20.xml and *.bpmn files, deploys them and exposes the engine services as Spring beans.

A request moves through the engine like this:

  1. Your code calls
  2. Flowable creates a process instance and runs automated steps until it reaches a wait state.
  3. At a user task, it writes a task row and commits. The thread returns.
  4. A person claims and completes the task through your API, which calls
  5. Flowable evaluates the next gateway, runs the matching service task and calls your Spring bean.
  6. The instance reaches an end event. Runtime rows are removed and the history rows stay.

Because the engine shares your Spring context, service tasks can call any bean, and engine writes join the same transaction as your own repository calls.

Flowable Spring Boot Example: Build an Expense Approval Workflow

This example covers the full path from dependency to running process. The rules:

  1. An employee submits an expense claim with an amount.
  2. Claims of $500 or less are approved automatically.
  3. Claims above $500 go to the
  4. If no manager acts within 48 hours, the engine sends a reminder.
  5. Approved claims are reimbursed. Rejected claims end the process.

Step 1: Add the Flowable Spring Boot Starter

Add the starter and a database driver. H2 is fine for local work; use PostgreSQL or MySQL anywhere else.

<properties>
    <java.version>17</java.version>
    <!-- Use the latest 7.x release from Maven Central -->
    <flowable.version>7.1.0</flowable.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>  

Need BPMN only? Swap in flowable-spring-boot-starter-process to skip the CMMN, DMN and form engines.

Then set a few properties in application.properties:

spring.datasource.url=jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=

# Create/upgrade Flowable tables on startup (fine for local; see "Mistakes" below for production)
flowable.database-schema-update=true
# Needed for timer events to fire
flowable.async-executor-activate=true

Step 2: Define the BPMN 2.0 Process

Save this as src/main/resources/processes/expense-approval.bpmn20.xml. You can draw it in the Flowable modeler or an IDE plugin; the tool generates XML in this shape.

<?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:flowable="http://flowable.org/bpmn"
             targetNamespace="https://7span.com/examples">

  <process id="expenseApproval" name="Expense Approval" isExecutable="true">

    <startEvent id="submitted"/>
    <sequenceFlow id="f1" sourceRef="submitted" targetRef="amountCheck"/>

    <!-- Route on amount: over 500 needs a manager, everything else auto-approves -->
    <exclusiveGateway id="amountCheck" default="autoApprove"/>
    <sequenceFlow id="needsManager" sourceRef="amountCheck" targetRef="managerApproval">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${amount > 500}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="autoApprove" sourceRef="amountCheck" targetRef="reimburse"/>

    <userTask id="managerApproval" name="Approve expense claim"
              flowable:candidateGroups="managers"/>

    <!-- Non-interrupting timer: remind managers after 48 hours, task stays open -->
    <boundaryEvent id="reminderTimer" attachedToRef="managerApproval" cancelActivity="false">
      <timerEventDefinition>
        <timeDuration>PT48H</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="f2" sourceRef="reminderTimer" targetRef="sendReminder"/>
    <serviceTask id="sendReminder" name="Send reminder"
                 flowable:delegateExpression="${reminderService}"/>
    <sequenceFlow id="f3" sourceRef="sendReminder" targetRef="reminderSent"/>
    <endEvent id="reminderSent"/>

    <sequenceFlow id="f4" sourceRef="managerApproval" targetRef="decision"/>
    <exclusiveGateway id="decision" default="rejectedFlow"/>
    <sequenceFlow id="approvedFlow" sourceRef="decision" targetRef="reimburse">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approved}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="rejectedFlow" sourceRef="decision" targetRef="rejected"/>
    <endEvent id="rejected"/>

    <serviceTask id="reimburse" name="Process reimbursement"
                 flowable:delegateExpression="${reimbursementService}"/>
    <sequenceFlow id="f5" sourceRef="reimburse" targetRef="paid"/>
    <endEvent id="paid"/>

  </process>
</definitions>

Read the business rules straight off the file. ${amount > 500} sends the claim to a user task; the gateway's default flow sends everything else to the reimbursement step. The timer has cancelActivity="false", so the reminder fires while the manager's task stays open.

Step 3: Connect Spring Beans to the Service Tasks

flowable:delegateExpression="${reimbursementService}" resolves to a Spring bean by name. The bean implements Flowable's JavaDelegate interface.

@Component("reimbursementService")
public class ReimbursementService implements JavaDelegate {

    private static final Logger log = LoggerFactory.getLogger(ReimbursementService.class);

    @Override
    public void execute(DelegateExecution execution) {
        String employeeId = (String) execution.getVariable("employeeId");
        Number amount = (Number) execution.getVariable("amount");

        // Call your payments client here
        log.info("Reimbursing {} to employee {}", amount, employeeId);

        execution.setVariable("reimbursedAt", Instant.now().toString());
    }
}

@Component("reminderService")
public class ReminderService implements JavaDelegate {

    private static final Logger log = LoggerFactory.getLogger(ReminderService.class);

    @Override
    public void execute(DelegateExecution execution) {
        log.info("Expense {} still waiting on a manager after 48h",
                execution.getProcessInstanceId());
        // Send email or Slack notification here
    }
}

Because these are normal Spring components, you can inject repositories, REST clients or anything else from your context.

Step 4: Start Processes and Complete Tasks

Inject RuntimeService to start instances and TaskService to work with the manager queue.

@Service
public class ExpenseWorkflowService {

    private final RuntimeService runtimeService;
    private final TaskService taskService;

    public ExpenseWorkflowService(RuntimeService runtimeService, TaskService taskService) {
        this.runtimeService = runtimeService;
        this.taskService = taskService;
    }

    public String submit(String employeeId, double amount) {
        ProcessInstance instance = runtimeService.startProcessInstanceByKey(
                "expenseApproval",
                Map.of("employeeId", employeeId, "amount", amount));
        return instance.getId();
    }

    public List<Task> pendingForManagers() {
        return taskService.createTaskQuery()
                .taskCandidateGroup("managers")
                .orderByTaskCreateTime().asc()
                .list();
    }

    public void decide(String taskId, String managerId, boolean approved) {
        taskService.claim(taskId, managerId);
        taskService.complete(taskId, Map.of("approved", approved));
    }
}

Call submit("emp-42", 320) and the instance runs straight through to paid. Call submit("emp-42", 1200) and it stops at managerApproval. Once decide(...) runs with approved = true, Flowable moves to reimbursementService, runs the payout logic and ends the instance.

Step 5: Read the Audit Trail

HistoryService answers the questions auditors ask: who approved it, which path ran and how long each step took.

List<HistoricActivityInstance> steps = historyService
        .createHistoricActivityInstanceQuery()
        .processInstanceId(processInstanceId)
        .orderByHistoricActivityInstanceStartTime().asc()
        .list();

steps.forEach(s -> log.info("{} | {} | {} ms | {}",
        s.getActivityId(), s.getAssignee(), s.getDurationInMillis(), s.getEndTime()));

Step 6: Test the Process

A @SpringBootTest with H2 runs the real engine, so you can assert routing without mocks.

@SpringBootTest
class ExpenseApprovalTest {

    @Autowired ExpenseWorkflowService workflow;
    @Autowired RuntimeService runtimeService;
    @Autowired TaskService taskService;

    @Test
    void smallClaimsSkipTheManager() {
        String id = workflow.submit("emp-1", 300);
        assertThat(runtimeService.createProcessInstanceQuery()
                .processInstanceId(id).count()).isZero();   // already finished
    }

    @Test
    void largeClaimsWaitForAManager() {
        String id = workflow.submit("emp-1", 900);
        Task task = taskService.createTaskQuery().processInstanceId(id).singleResult();
        assertThat(task.getTaskDefinitionKey()).isEqualTo("managerApproval");
    }
}

Flowable vs Camunda: Which Java Workflow Engine Should You Pick?

Flowable and Camunda share a common ancestor in Activiti, and both execute BPMN 2.0. The split today is architectural. Flowable embeds in your JVM and stores state in your database. Camunda 8 runs on the Zeebe engine as a separate cluster that your services call over the network, and Camunda 7 Community Edition reached end of life in October 2025.

Flowable (open source)Camunda 8
Runs whereInside your Spring Boot appSeparate orchestration cluster
State storageYour relational databaseZeebe's own storage
StandardsBPMN 2.0, CMMN, DMNBPMN 2.0, DMN
LicenceApache 2.0Check current terms for self-managed production use
Best fitTeams that want one deployable and one databaseTeams running high-volume orchestration across many services

For a team moving off Camunda 7 that wants to keep the embedded model, Flowable is the shorter migration because the programming model (RuntimeService, TaskService, JavaDelegate) will feel familiar. Model your own top three processes in each before committing.

What Mistakes Should You Avoid With Flowable in Production?

Most Flowable problems in production come from configuration that worked in a demo. These five show up most:

  • Leaving
  • Disabling the async executor. Timers and async service tasks never fire without it. If a reminder "does nothing", check
  • Storing large objects as variables. Process variables are serialized into the database. Store an ID and load the entity in your delegate.
  • Changing a deployed process key. Running instances stay on the version they started with. Keep the key stable and let Flowable version the definition.
  • Skipping history cleanup. The

One more rule: keep business logic out of BPMN expressions. ${amount > 500} is fine. A twenty-line JUEL expression is a bug you can't unit test. Put that logic in a bean and call it.

Where Is a Flowable Workflow Engine Useful?

Flowable fits any process with several steps, a wait state or a hand-off between people and systems. In practice that covers four common groups of business software.

  • Approvals: leave requests, expense claims, purchase orders and document sign-offs.
  • Customer onboarding: multi-stage KYC, document checks and account activation, common in
  • Order fulfilment: inventory checks, payment capture, shipping and refunds.
  • Support escalations: reassigning tickets automatically when an SLA timer expires.

Legacy systems are another strong candidate. When an older app hides its process in stored procedures and status codes, extracting that flow into BPMN 2.0 is often the first step of a legacy app modernization project, because the diagram doubles as documentation.

Where to Start

Pick one workflow in your codebase that already has too many status flags. Model it with a start event, one or two user tasks, a gateway and a service task. Run it on H2 with the test above, then point it at your real database.

We've built Spring Boot backends for products like Testiqo and Unified POS, and our Java developers can join your team to design and ship workflow-heavy services. For more Spring Boot reading, see our Spring AI beginner's guide.

To scope a workflow build, book a 30-minute technical call with an engineering lead and leave with a first-pass architecture for your process.
Book a Call

Frequently Asked Questions

What is Flowable used for?

Flowable runs BPMN 2.0 business processes inside Java applications. Teams use it for approval chains, customer onboarding, order fulfilment and SLA escalations. It persists each process instance to a relational database, manages user tasks and timers, and records a full history of every step for auditing.

Is Flowable free to use?

Yes. The Flowable engines (BPMN, CMMN and DMN) are open source under the Apache 2.0 licence, so you can use them in commercial products without fees. Flowable also sells enterprise products with extra modelling and operations tooling, which are separate from the open-source engine covered in this guide.

Which Flowable version works with Spring Boot 3?

Flowable 7.x targets Spring Boot 3 and Java 17 or later. Teams still on Spring Boot 2 and older Java versions use the Flowable 6.x line. Check Maven Central for the latest 7.x release of flowable-spring-boot-starter before you add it to a new project.

What is the difference between a user task and a service task in BPMN 2.0?

A user task pauses the process until a person claims and completes it, such as a manager approving an expense. A service task runs automatically by calling code, in Flowable usually a Spring bean that implements JavaDelegate. Most real workflows mix both.

Is Flowable better than Camunda?

It depends on architecture. Flowable embeds in your Spring Boot app and uses your database, which suits teams that want one deployable. Camunda 8 runs as a separate cluster built for high-volume orchestration across services. Teams leaving Camunda 7, whose Community Edition reached end of life in October 2025, often find Flowable the closer fit.

Arham Shah
SOFTWARE ENGINEER
I enjoy solving complex problems and building meaningful software. Working across Java, Spring Boot, React, databases, and AI, I turn ideas into practical, scalable solutions. Always learning, exploring new technologies, and improving the way I build.
India (HQ)

201, iSquare Corporate Park, Ahmedabad-380060, Gujarat, India

+91 77 97 977 977
Canada

24 Merlot Court, Timberlea, NS B3T 0C2, Canada

+1 902-333-0067

For Sales

YO@7SPAN.COM

Looking For Jobs

Apply Now
Making It Possible Light