Backend Development 10 min read

Integrating Activiti Workflow Engine with Spring Boot: Configuration, Code Samples, and Usage

This article explains how to integrate the Activiti BPMN 2.0 workflow engine into a Spring Boot application, covering Maven dependencies, data source and Activiti configuration, Spring MVC setup, Java code for starting, approving, and querying leave requests, as well as a simple AngularJS front‑end for task management.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Integrating Activiti Workflow Engine with Spring Boot: Configuration, Code Samples, and Usage

Activiti is an open‑source BPMN 2.0 workflow engine that can be embedded in Java applications. By adding the <dependency><groupId>org.activiti</groupId><artifactId>activiti-spring-boot-starter-basic</artifactId><version>6.0.0</version></dependency> to a Spring Boot project, you enable workflow capabilities.

The required configuration includes a data source definition and Activiti settings in application.yml (or application.properties ), for example:

server:
  port: 8081
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/act5?useSSL=true
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: root
activiti:
  database-schema-update: true
  check-process-definitions: true
  process-definition-location-prefix: classpath:/processes/
  history-level: full

A Spring MVC configuration class annotated with @EnableWebMvc and @Configuration registers static resource handlers for /static/** and /templates/** , allowing Thymeleaf views to be served.

To start a leave‑request process, the service defines a constant PROCESS_DEFINE_KEY = "vacationProcess" and uses the runtimeService.startProcessInstanceByKey method, setting variables such as applyUser , days , and reason . The current task is claimed and completed with those variables.

For approval, the boss queries tasks with taskService.createTaskQuery().taskCandidateUser(userName).orderByTaskCreateTime().desc().list() , maps each Task to a VacTask DTO, and then completes the task by posting the result (approved or rejected) along with auditor information.

Historical records are retrieved from the Activiti history tables using historyService.createHistoricProcessInstanceQuery() filtered by the process definition key and start user. Each historic instance is converted back into a Vacation VO by loading its historic variables via historyService.createHistoricVariableInstanceQuery() and a utility method ActivitiUtil.setVars that reflects variable names onto the VO fields.

The front‑end uses AngularJS to display pending tasks in a table, showing task name, creation time, applicant, leave dates, and reason, with buttons to approve or reject. Sample HTML snippets:

<div ng-controller="myAudit">
  <h2 ng-init="myAudit()">待我审核的请假</h2>
  <table border="0">
    <tr>
      <td>任务名称</td>
      <td>任务时间</td>
      <td>申请人</td>
      <td>申请时间</td>
      <td>天数</td>
      <td>事由</td>
      <td>操作</td>
    </tr>
    <tr ng-repeat="vacTask in vacTaskList">
      <td>{{vacTask.name}}</td>
      <td>{{vacTask.createTime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
      <td>{{vacTask.vac.applyUser}}</td>
      <td>{{vacTask.vac.applyTime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
      <td>{{vacTask.vac.days}}</td>
      <td>{{vacTask.vac.reason}}</td>
      <td>
        <button type="button" ng-click="passAudit(vacTask.id, 1)">审核通过</button>
        <button type="button" ng-click="passAudit(vacTask.id, 0)">审核拒绝</button>
      </td>
    </tr>
  </table>
</div>

The complete source code is available at https://gitee.com/yawensilence/activiti-demo6-springboot , providing a ready‑to‑run example of a Spring Boot + Activiti 6 workflow application.

JavaWorkflowSpring BootActivitiAngularJS
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

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.