Backend Development 20 min read

Integrating Flowable Workflow Engine with Spring Boot: A Comprehensive Guide

This article provides a step‑by‑step tutorial on using the Flowable BPMN engine within a Spring Boot project, covering workflow fundamentals, key concepts, Maven dependencies, BPMN diagram creation, service task implementation, runtime APIs, unit testing, and common troubleshooting tips.

Top Architect
Top Architect
Top Architect
Integrating Flowable Workflow Engine with Spring Boot: A Comprehensive Guide

The article begins with a brief history of Java‑based workflow engines, explaining how jBPM evolved into Activiti, Flowable, and Camunda, and summarizing the distinctive features of each engine.

It then introduces the core BPMN concepts—events, sequence flows, tasks, and gateways—using a simple leave‑request process as an example, and illustrates each element with diagrams.

Spring Boot Integration

1. Create a Spring Boot project and add the Flowable starter dependency:

<dependency>
  <groupId>org.flowable</groupId>
  <artifactId>flowable-spring-boot-starter</artifactId>
  <version>6.7.2</version>
</dependency>

2. Configure the MySQL datasource in application.yml (or application.properties ) so that Flowable can create its tables automatically.

3. Place BPMN files (e.g., ask_for_leave.bpmn20.xml ) under resources/processes . The engine will deploy them at startup.

4. Define the process flow: start event → employee user task → team‑lead approval gateway → manager approval gateway → end events, with exclusive gateways handling “approve” or “reject” paths.

Service Task Implementation

@Slf4j
@Component
public class LeaveFailService implements JavaDelegate {
    @Override
    public void execute(DelegateExecution delegateExecution) {
        log.info("审批不通过{}", delegateExecution.getCurrentActivityId());
    }
}

This class is referenced in the BPMN as the flowable:class for the “Send Failure Notification” service task.

Process Diagram API

A REST controller exposes an endpoint /pic that generates a PNG diagram highlighting active activities. It retrieves the process instance, active activity IDs, and uses Flowable’s ProcessDiagramGenerator to stream the image.

@RestController
public class LeaveController {
    @Autowired RuntimeService runtimeService;
    @Autowired RepositoryService repositoryService;
    @Autowired ProcessEngine processEngine;

    @GetMapping("/pic")
    public void showPic(HttpServletResponse resp, String processId) throws Exception {
        // ... (code omitted for brevity) ...
    }
}

Unit Tests

JUnit tests demonstrate how to start the process, complete user tasks, and set process variables such as assignee IDs and approval results.

@SpringBootTest
@Slf4j
@ActiveProfiles("dev")
public class ProcessApplicationTests {
    @Autowired RuntimeService runtimeService;
    @Autowired TaskService taskService;
    // ... test methods for starting process, submitting tasks, approvals ...
}

Common Issues

• Missing fonts cause diagram text to appear as garbled characters; the solution is to install appropriate fonts or configure Flowable’s font settings.

@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer
{
    @Override
    public void configure(SpringProcessEngineConfiguration cfg) {
        cfg.setActivityFontName("宋体");
        cfg.setLabelFontName("宋体");
        cfg.setAnnotationFontName("宋体");
    }
}

• Modifying a BPMN file after a process instance has started does not affect the running instance because the definition is already persisted.

Overall, the guide equips developers with everything needed to embed a robust, visual workflow engine into a Spring Boot microservice, from Maven setup to runtime monitoring and troubleshooting.

backendjavaworkflowBPMNSpring BootFlowable
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.