Mastering Activiti 7: From Workflow Basics to Full Deployment and Management

This comprehensive guide explains workflow concepts, introduces the Activiti 7 BPMN engine, walks through environment setup, configuration, database schema creation, process definition, deployment, instance start, task handling, and history inspection with complete Java code examples.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Mastering Activiti 7: From Workflow Basics to Full Deployment and Management

Workflow Introduction

A workflow automates business processes by passing documents, information, or tasks among participants according to predefined rules to achieve a business goal.

Workflow System

A software system that includes workflow functionality is called a workflow system; it manages business processes automatically, improving scalability and maintainability.

Applicable Industries

Consumer goods

Manufacturing

Telecommunications

Financial services

Logistics

Property management

Government and education

Specific Applications

Key business processes such as order handling, quotation, contract review, and supply chain management.

Administrative forms like travel requests, overtime, leave, vehicle use, and daily reports.

HR processes including training, performance appraisal, and employee record management.

Financial processes such as payment requests, receivables, expense reimbursement, and budgeting.

Customer service tasks like information management, complaints, and after‑sale service.

Special services such as ISO procedures, quality management, product data, customs clearance, and cargo tracking.

Implementation Methods

Before dedicated workflow engines, processes were controlled by status fields, which required code changes whenever the process changed. A professional workflow engine allows the process to evolve without modifying application code.

Activiti 7 Overview

Introduction

Activiti was launched by Alfresco in 2010 under the leadership of Tom Baeyens, the original architect of jBPM. It is a workflow engine that extracts complex business processes and defines them with BPMN 2.0.

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

Current version: Activiti7.0.0.Beta

BPM

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

BPM Software

BPM software provides tools for modeling, automating, monitoring, and optimizing business processes, reducing costs and increasing profit.

BPMN

Business Process Model and Notation (BPMN) is a standard set of symbols for describing processes, originally created by BPMI and now maintained by OMG.

Typical BPMN symbols include events (circles), activities (rounded rectangles), and gateways (diamonds) such as exclusive, parallel, inclusive, and event gateways.

Activiti Environment

Development Environment

JDK 1.8 or higher

MySQL 5 or higher

Tomcat 8.5

IntelliJ IDEA

Install the Activiti Designer plugin in IDEA (Settings → Plugins → Search "actiBPM" → Install → Restart).

Downloading Activiti 7

<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>

Database Support

Activiti supports MySQL, Oracle, PostgreSQL, SQL Server, DB2, H2, and others.

Creating Database Tables

CREATE DATABASE activiti DEFAULT CHARACTER SET utf8;

Define activiti.cfg.xml with a processEngineConfiguration bean (JDBC driver, URL, username, password, and databaseSchemaUpdate=true).

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
   <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
   <property name="jdbcUrl" value="jdbc:mysql:///activiti"/>
   <property name="jdbcUsername" value="root"/>
   <property name="jdbcPassword" value="123456"/>
   <property name="databaseSchemaUpdate" value="true"/>
</bean>

Running a simple test class creates 25 Activiti tables (ACT_RE_*, ACT_RU_*, ACT_HI_*, ACT_GE_*).

package com.itheima.activiti01.test;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.junit.Test;

public class TestDemo {
   @Test
   public void testCreateDbTable() {
      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
      System.out.println(processEngine);
   }
}

Table Naming Rules

All tables start with ACT_ followed by a two‑letter module code: RE (repository), RU (runtime), HI (history), GE (general).

Activiti Class Diagram

In newer versions, IdentityService and FormService have been removed.

activiti.cfg.xml

This Spring XML file defines the process engine configuration, data source, and transaction manager.

Process Engine Configuration

StandaloneProcessEngineConfiguration

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
   <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
   <property name="jdbcUrl" value="jdbc:mysql:///activiti"/>
   <property name="jdbcUsername" value="root"/>
   <property name="jdbcPassword" value="123456"/>
   <property name="databaseSchemaUpdate" value="true"/>
</bean>

SpringProcessEngineConfiguration

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
   <property name="dataSource" ref="dataSource"/>
   <property name="transactionManager" ref="transactionManager"/>
   <property name="databaseSchemaUpdate" value="drop-create"/>
   <property name="jobExecutorActivate" value="false"/>
</bean>

Service Interfaces

Activiti provides several services:

RepositoryService : Deploys and manages process definitions and resources.

RuntimeService : Starts process instances and queries runtime data.

TaskService : Queries and completes user tasks.

HistoryService : Retrieves historic process, activity, and task data.

ManagementService : Engine management and maintenance functions.

Activiti Getting Started

To create a workflow you need to define a BPMN process, deploy it, and start an instance.

Process Symbols

Key BPMN symbols include events, activities, gateways (exclusive, parallel, inclusive, event), and sequence flows.

Process Designer Usage (IDEA)

Create a .bpmn file via New → BpmnFile, set the process key and task assignees in the Properties view, then save. The designer can export the diagram as a PNG image.

Process Definition Deployment

Deploy a single BPMN file and its PNG image using the RepositoryService.

public void testDeployment() {
   ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
   RepositoryService repo = engine.getRepositoryService();
   Deployment deployment = repo.createDeployment()
       .addClasspathResource("bpmn/evection.bpmn")
       .addClasspathResource("bpmn/evection.png")
       .name("出差申请流程")
       .deploy();
   System.out.println("部署id=" + deployment.getId());
   System.out.println("部署名称=" + deployment.getName());
}

Alternatively, deploy a ZIP containing the resources.

public void deployProcessByZip() throws IOException {
   InputStream is = getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip");
   ZipInputStream zip = new ZipInputStream(is);
   RepositoryService repo = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
   Deployment deployment = repo.createDeployment().addZipInputStream(zip).deploy();
   System.out.println("部署id=" + deployment.getId());
}

Start Process Instance

public void testStartProcess() {
   ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
   RuntimeService runtime = engine.getRuntimeService();
   ProcessInstance instance = runtime.startProcessInstanceByKey("myEvection");
   System.out.println("定义id=" + instance.getProcessDefinitionId());
   System.out.println("实例id=" + instance.getId());
   System.out.println("当前活动=" + instance.getActivityId());
}

Task Query

public void testFindPersonalTaskList() {
   String assignee = "zhangsan";
   ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
   TaskService taskService = engine.getTaskService();
   List<Task> tasks = taskService.createTaskQuery()
       .processDefinitionKey("myEvection")
       .taskAssignee(assignee)
       .list();
   for (Task task : tasks) {
       System.out.println("实例id=" + task.getProcessInstanceId());
       System.out.println("任务id=" + task.getId());
       System.out.println("负责人=" + task.getAssignee());
       System.out.println("名称=" + task.getName());
   }
}

Task Completion

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

Process Definition Query

public void queryProcessDefinition() {
   ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
   RepositoryService repo = engine.getRepositoryService();
   List<ProcessDefinition> list = repo.createProcessDefinitionQuery()
       .processDefinitionKey("myEvection")
       .orderByProcessDefinitionVersion().desc()
       .list();
   for (ProcessDefinition pd : list) {
       System.out.println("定义id=" + pd.getId());
       System.out.println("名称=" + pd.getName());
       System.out.println("Key=" + pd.getKey());
       System.out.println("版本=" + pd.getVersion());
       System.out.println("部署ID=" + pd.getDeploymentId());
   }
}

Process Deletion

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

Process Resource Download

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());
   FileOutputStream pngOut = new FileOutputStream("d:/evectionflow.png");
   FileOutputStream bpmnOut = new FileOutputStream("d:/evectionflow.bpmn");
   IOUtils.copy(pngIn, pngOut);
   IOUtils.copy(bpmnIn, bpmnOut);
   pngOut.close(); bpmnOut.close(); pngIn.close(); bpmnIn.close();
}

Process History Viewing

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

The tutorial covered workflow fundamentals, Activiti 7 installation, configuration, database schema creation, process definition, deployment, instance start, task handling, deletion, resource export, and history inspection. For advanced features such as suspension, activation, and process variables, refer to the official Activiti documentation and related 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.

JavaActiviti
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

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.