Comprehensive Guide to Activiti 7 Workflow Engine: Concepts, Setup, Deployment, and Usage

This article provides an in‑depth tutorial on Activiti 7 workflow management, covering workflow concepts, system architecture, BPMN modeling, environment setup, Maven dependencies, database configuration, deployment methods, process execution, task handling, and historical data retrieval for Java backend development.

Architecture Digest
Architecture Digest
Architecture Digest
Comprehensive Guide to Activiti 7 Workflow Engine: Concepts, Setup, Deployment, and Usage

1. Workflow Introduction

A workflow automates business processes across multiple participants according to predefined rules, improving manageability and scalability of the system.

1.1 Concept

Workflow (Workflow) is the computer‑based automation of business processes, enabling documents, information, or tasks to be passed automatically among participants to achieve business goals.

1.2 Workflow System

A software system that includes workflow capabilities is called a workflow system. It assists in managing business processes, though the core system remains the business logic.

1.3 Applicable Industries

Consumer goods, manufacturing, telecom, finance, logistics, property management, large multinational corporations, government agencies, research institutes, and education services.

1.4 Typical Applications

Key business processes (order, quotation, contract review, etc.), administrative forms (travel request, overtime, leave, vehicle usage, procurement), HR management (training, performance appraisal, position changes), finance (payment request, reimbursement, budgeting), customer service, and special services such as ISO compliance and trade customs.

1.5 Implementation Methods

Before dedicated workflow engines, process control was often handled by status fields in database tables, which required code changes whenever the process changed.

2. Activiti 7 Overview

2.1 Introduction

Activiti is an open‑source BPM workflow engine originally created by the former jBPM architect Tom Baeyens. It uses BPMN 2.0 for process modeling, allowing business processes to be defined separately from the application code.

Official website: https://www.activiti.org/

2.1.1 BPM

Business Process Management (BPM) standardizes end‑to‑end processes to continuously improve organizational efficiency.

2.1.2 BPM Software

BPM software integrates people, systems, and processes, providing modeling, automation, monitoring, and optimization.

2.1.3 BPMN

BPMN (Business Process Model and Notation) is the standard graphical notation for modeling business processes, maintained by OMG.

Example BPMN XML:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" ...>
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"/>
    <userTask id="usertask1" name="Create Leave Request"/>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"/>
    ...
  </process>
</definitions>

2.2 Usage Steps

Deploy Activiti

Activiti is a set of JARs; the business system accesses its API to manage processes.

Process Definition

Use the Activiti Designer (activity‑designer) to create .bpmn files that define the process.

Deploy Process Definition

Deploy the .bpmn (and optional .png) files via the RepositoryService API or a ZIP package.

Start a Process Instance

Calling RuntimeService.startProcessInstanceByKey launches a new instance of the defined workflow.

User Task Query

TaskService can query pending tasks for a specific assignee.

User Task Completion

TaskService.complete(taskId) marks a task as finished.

Process End

When no further tasks exist, the process instance ends automatically.

3. Activiti Environment

3.1 Development Environment

JDK 1.8+

MySQL 5+

Tomcat 8.5

IDEA

3.2 Activiti Version

Using Activiti7.0.0.Beta1 with Spring 5 support.

3.2.1 Download Activiti 7

Download URL: http://activiti.org/download.html Maven dependency management snippet:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-dependencies</artifactId>
      <version>7.0.0.Beta1</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
    ...
  </dependencies>
</dependencyManagement>

3.2.2 Database Support

Activiti supports H2, MySQL, Oracle, PostgreSQL, MSSQL, DB2.

3.3 Creating Database Tables

SQL to create database:

CREATE DATABASE activiti DEFAULT CHARACTER SET utf8;

Java test class to generate tables using ProcessEngines.getDefaultProcessEngine().

package com.itheima.activiti01.test;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.junit.Test;
public class TestDemo {
  @Test
  public void testCreateDbTable() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    System.out.println(processEngine);
  }
}

3.4 Table Structure

All Activiti tables start with ACT_ and are divided into RE (repository), RU (runtime), HI (history), and GE (general) groups.

4. Activiti Class Diagram

Shows core services: RepositoryService, RuntimeService, TaskService, HistoryService, ManagementService, IdentityService, etc.

4.1 Process Engine Configuration

Two main configurations: StandaloneProcessEngineConfiguration (stand‑alone) and SpringProcessEngineConfiguration (Spring integration).

4.1.1 Standalone

Define a bean named processEngineConfiguration with JDBC properties and databaseSchemaUpdate set to true.

4.1.2 Spring

Define processEngineConfiguration bean of class org.activiti.spring.SpringProcessEngineConfiguration with dataSource and transactionManager references.

4.2 Creating the Process Engine

Use ProcessEngines.getDefaultProcessEngine() for default configuration or build manually via ProcessEngineConfiguration.

4.3 Service Interfaces

RepositoryService : Deploy and manage process definitions.

RuntimeService : Manage running process instances.

TaskService : Query and complete user tasks.

HistoryService : Access historical execution data.

ManagementService : Engine administration.

5. Activiti Hands‑On

5.1 Process Modeling

Use BPMN 2.0 symbols (Events, Activities, Gateways, Flows) in the Activiti Designer plugin for IntelliJ IDEA. Assign task assignees (e.g., zhangsan, jerry, jack, rose) and set the process key.

5.2 Deploying the Process

Java code example:

@Test
public void testDeployment() {
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repo = engine.getRepositoryService();
  Deployment deployment = repo.createDeployment()
      .addClasspathResource("bpmn/evection.bpmn")
      .addClasspathResource("bpmn/evection.png")
      .name("Leave Request Process")
      .deploy();
  System.out.println("Deployment id: " + deployment.getId());
  System.out.println("Deployment name: " + deployment.getName());
}

Alternatively, deploy a ZIP containing the resources.

5.3 Starting a Process Instance

@Test
public void testStartProcess() {
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  RuntimeService runtime = engine.getRuntimeService();
  ProcessInstance instance = runtime.startProcessInstanceByKey("myEvection");
  System.out.println("Definition id: " + instance.getProcessDefinitionId());
  System.out.println("Instance id: " + instance.getId());
  System.out.println("Current activity id: " + instance.getActivityId());
}

5.4 Task Query and Completion

@Test
public void testFindPersonalTaskList() {
  String assignee = "zhangsan";
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  TaskService taskService = engine.getTaskService();
  List<Task> list = taskService.createTaskQuery()
      .processDefinitionKey("myEvection")
      .taskAssignee(assignee)
      .list();
  for (Task task : list) {
    System.out.println("ProcessInstanceId: " + task.getProcessInstanceId());
    System.out.println("TaskId: " + task.getId());
    System.out.println("Assignee: " + task.getAssignee());
    System.out.println("Name: " + task.getName());
  }
}

@Test
public void completeTask() {
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  TaskService taskService = engine.getTaskService();
  Task task = taskService.createTaskQuery()
      .processDefinitionKey("myEvection")
      .taskAssignee("zhangsan")
      .singleResult();
  taskService.complete(task.getId());
}

5.5 Process Definition Query

@Test
public void queryProcessDefinition() {
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repo = engine.getRepositoryService();
  List<ProcessDefinition> defs = repo.createProcessDefinitionQuery()
      .processDefinitionKey("myEvection")
      .orderByProcessDefinitionVersion().desc()
      .list();
  for (ProcessDefinition pd : defs) {
    System.out.println("ID=" + pd.getId());
    System.out.println("Name=" + pd.getName());
    System.out.println("Key=" + pd.getKey());
    System.out.println("Version=" + pd.getVersion());
    System.out.println("DeploymentId=" + pd.getDeploymentId());
  }
}

5.6 Deleting Deployments

public void deleteDeployment() {
  String deploymentId = "1";
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repo = engine.getRepositoryService();
  // Normal delete (fails if instances exist)
  repo.deleteDeployment(deploymentId);
  // Cascade delete (removes instances as well)
  // repo.deleteDeployment(deploymentId, true);
}

5.7 Downloading Process Resources

Retrieve BPMN and PNG files from the repository using RepositoryService.getResourceAsStream and write them to the file system (requires Apache Commons IO).

public void queryBpmnFile() throws IOException {
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repo = engine.getRepositoryService();
  ProcessDefinition pd = repo.createProcessDefinitionQuery()
      .processDefinitionKey("myEvection")
      .singleResult();
  String deploymentId = pd.getDeploymentId();
  InputStream pngIn = repo.getResourceAsStream(deploymentId, pd.getDiagramResourceName());
  InputStream bpmnIn = repo.getResourceAsStream(deploymentId, pd.getResourceName());
  File pngFile = new File("d:/evectionflow.png");
  File bpmnFile = new File("d:/evectionflow.bpmn");
  try (FileOutputStream pngOut = new FileOutputStream(pngFile);
       FileOutputStream bpmnOut = new FileOutputStream(bpmnFile)) {
    IOUtils.copy(pngIn, pngOut);
    IOUtils.copy(bpmnIn, bpmnOut);
  }
}

5.8 Viewing Historical Data

@Test
public void findHistoryInfo() {
  ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
  HistoryService history = engine.getHistoryService();
  List<HistoricActivityInstance> list = history.createHistoricActivityInstanceQuery()
      .processDefinitionId("myEvection:1:4")
      .orderByHistoricActivityInstanceStartTime().asc()
      .list();
  for (HistoricActivityInstance hi : list) {
    System.out.println(hi.getActivityId());
    System.out.println(hi.getActivityName());
    System.out.println(hi.getProcessDefinitionId());
    System.out.println(hi.getProcessInstanceId());
    System.out.println("<==========================>");
  }
}

Conclusion

This tutorial covered the fundamentals of Activiti workflow management, including environment setup, process modeling, deployment, execution, task handling, and historical queries. For advanced features such as suspension, activation, and process variables, refer to the linked CSDN articles.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavadatabaseworkflowBPMNspringActiviti
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

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.