Activiti 7 Workflow Engine: Concepts, Configuration, Deployment, and Operations
This article provides a comprehensive guide to the Activiti 7 workflow engine, covering its core concepts, Maven dependencies, XML configuration, engine creation methods, service interfaces, process deployment, instance management, task handling, variable usage, gateway types, and integration with Spring and Spring Boot, all illustrated with practical code examples.
Concept – A workflow automates business processes by passing documents, information, or tasks between participants according to predefined rules to achieve a business goal.
Activiti 7 Overview – Activiti is a BPMN 2.0‑based workflow engine that extracts complex business logic from applications, allowing process definitions to be managed independently, reducing system coupling and maintenance cost.
Maven Dependencies
<dependencies>
<!-- core engine -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>6.0.0</version>
</dependency>
<!-- Spring integration -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>6.0.0</version>
</dependency>
...
</dependencies>activiti.cfg.xml – The Spring configuration file defines the data source, transaction manager, and engine properties such as databaseSchemaUpdate and mail server settings.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- DBCP connection pool -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/activiti"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!-- Process engine configuration -->
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="asyncExecutorActivate" value="false"/>
<property name="mailServerHost" value="mail.my-corp.com"/>
<property name="mailServerPort" value="5025"/>
</bean>
</beans>Engine Creation – Two approaches are shown:
// Default engine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// Custom configuration
ProcessEngineConfiguration cfg = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
ProcessEngine processEngine = cfg.buildProcessEngine();When the engine starts, Activiti creates 25 tables in the database.
Service Interfaces – The engine provides several services accessed via processEngine.getXxxService(): RepositoryService – Deploys and manages process definitions. RuntimeService – Starts process instances and queries runtime data. TaskService – Queries and completes user tasks. HistoryService – Retrieves historical execution data. ManagementService – Engine administration functions.
Process Deployment – Using RepositoryService to deploy a BPMN file (and optional PNG) or a ZIP containing multiple definitions:
public void deployment() {
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repo = engine.getRepositoryService();
Deployment deployment = repo.createDeployment()
.name("Travel Request")
.addClasspathResource("bpmn/evection.bpmn")
.addClasspathResource("bpmn/evection.png")
.deploy();
System.out.println("Deployment ID: " + deployment.getId());
}
public void deployProcessByZip() {
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repo = engine.getRepositoryService();
InputStream is = getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip");
ZipInputStream zip = new ZipInputStream(is);
Deployment deployment = repo.createDeployment().addZipInputStream(zip).deploy();
System.out.println("Deployment ID: " + deployment.getId());
}Starting a Process Instance
public void startProcess() {
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());
}Task Query and Completion
// Query tasks for a specific assignee
List<Task> tasks = taskService.createTaskQuery()
.processDefinitionKey("myEvection")
.taskAssignee("zhangsan")
.list();
// Complete a task
Task task = taskService.createTaskQuery()
.processDefinitionKey("myProcess_2")
.taskAssignee("wangcaiwu0")
.singleResult();
if (task != null) {
taskService.complete(task.getId(), variablesMap);
}Suspending and Activating Processes – Both whole process definitions and individual instances can be suspended or activated via RepositoryService or RuntimeService.
// Suspend or activate all instances of a definition
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("myEvection").singleResult();
if (pd.isSuspended()) {
repositoryService.activateProcessDefinitionById(pd.getId(), true, null);
} else {
repositoryService.suspendProcessDefinitionById(pd.getId(), true, null);
}
// Suspend or activate a single instance
ProcessInstance pi = runtimeService.createProcessInstanceQuery()
.processInstanceId("17501").singleResult();
if (pi.isSuspended()) {
runtimeService.activateProcessInstanceById(pi.getId());
} else {
runtimeService.suspendProcessInstanceById(pi.getId());
}Process Variables – Variables can be set at start time or during task completion. Complex objects must implement Serializable. Example POJO Evection is shown.
@Data @NoArgsConstructor @AllArgsConstructor
public class Evection implements Serializable {
private Long id;
private Integer days;
private String evectionName;
private Date startTime;
private Date endTime;
private String address;
private String reason;
}Variables are referenced in BPMN using UEL expressions such as ${assignee} or conditionals like ${days <= 3}.
Gateways – The article explains the four main gateway types:
ExclusiveGateway – chooses a single outgoing flow whose condition evaluates to true.
ParallelGateway – forks into parallel paths and joins them; conditions are ignored.
InclusiveGateway – may take multiple outgoing flows whose conditions are true; joins wait for all active tokens.
EventGateway – not detailed, but mentioned as a control element.
Spring Integration – Provides a full Spring XML configuration that defines the data source, process engine factory bean, and service beans, as well as transaction advice. A Spring Boot application.yml example shows properties for datasource and Activiti (schema update, history level, etc.).
# application.yml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/actspring
username: root
password: root
activiti:
database-schema-update: true
check-process-definitions: false
db-history-used: true
history-level: fullThe article ends with a call for discussion, community links, and promotional messages.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
