Activiti class diagram

Class 1 Diagram


In the new version, we can find that IdentityService and FormService have been deleted through experiments.

However, these two services are still available in the old version, which needs to be understood

2 activiti.cfg.xml

activiti's engine configuration file includes the definition of process engine configuration, data source definition, transaction manager, etc. This file is actually a spring configuration file.

3 process engine configuration class

The configuration class of the process engine (ProcessEngineConfiguration). The workflow engine procecengine can be created through ProcessEngineConfiguration. The two common methods are as follows:


3.1 StandaloneProcessEngineConfiguration

The standalone process engine configurationactiviti can be run separately to create a process engine, and the Activiti will handle transactions by itself.

Configuration file mode:

A bean with id processEngineConfiguration is usually defined in the activiti.cfg.xml configuration file

The method is as follows:

<bean id="processEngineConfiguration"
        <!--Configuration database related information-->
        <!--Database driven-->
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>
        <!--Database link-->
        <property name="jdbcUrl" value="jdbc:mysql:///activiti"/>
        <!--Database user name-->
        <property name="jdbcUsername" value="root"/>
        <!--Database password-->
        <property name="jdbcPassword" value="123456"/>
        <!--actviti Strategy of database table generation  true - If the corresponding table already exists in the database, it can be used directly. If it does not exist, it will be created-->
        <property name="databaseSchemaUpdate" value="true"/>

You can also join the connection pool:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql:///activiti"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
        <property name="maxActive" value="3"/>
        <property name="maxIdle" value="1"/>
    <!--In default mode bean of id  Fixed as processEngineConfiguration-->
    <bean id="processEngineConfiguration"
        <!--Introduce the link pool configured above-->
        <property name="dataSource" ref="dataSource"/>
        <!--actviti Strategy of database table generation  true - If the corresponding table already exists in the database, it can be used directly. If it does not exist, it will be created-->
        <property name="databaseSchemaUpdate" value="true"/>

3.2 SpringProcessEngineConfiguration

Integrate with Spring through org.activiti.spring.SpringProcessEngineConfiguration.

To create a spring and activiti integration profile:

activity-spring.cfg.xml (name can be modified)

<beans xmlns=""
    xmlns:xsi="" xmlns:mvc=""
    xmlns:aop="" xmlns:tx=""
 xsi:schemaLocation=" ">
    <!-- Workflow engine configuration bean -->
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
       <!-- data source -->
       <property name="dataSource" ref="dataSource" />
       <!-- use spring Transaction manager -->
       <property name="transactionManager" ref="transactionManager" />
       <!-- Database policy -->
       <property name="databaseSchemaUpdate" value="drop-create" />
       <!-- activiti Scheduled task closed -->
      <property name="jobExecutorActivate" value="false" />
    <!-- Process engine -->
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
       <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    <!-- Resource services service -->
    <bean id="repositoryService" factory-bean="processEngine"
       factory-method="getRepositoryService" />
    <!-- Process operation service -->
    <bean id="runtimeService" factory-bean="processEngine"
       factory-method="getRuntimeService" />
    <!-- task management service -->
    <bean id="taskService" factory-bean="processEngine"
       factory-method="getTaskService" />
    <!-- Historical management service -->
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
    <!-- user management  service -->
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
    <!-- Engine management service -->
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
    <!-- data source -->
    <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="mysql" />
       <property name="maxActive" value="3" />
       <property name="maxIdle" value="1" />
    <!-- Transaction manager -->
    <bean id="transactionManager"
       <property name="dataSource" ref="dataSource" />
    <!-- notice -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
           <!-- Communication behavior -->
           <tx:method name="save*" propagation="REQUIRED" />
           <tx:method name="insert*" propagation="REQUIRED" />
           <tx:method name="delete*" propagation="REQUIRED" />
           <tx:method name="update*" propagation="REQUIRED" />
           <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
           <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
    <!-- Slice, modify the tangent point configuration according to the specific project -->
    <aop:config proxy-target-class="true">
       <aop:advisor advice-ref="txAdvice"  pointcut="execution(* com.itheima.ihrm.service.impl.*.(..))"* />

Create processEngineConfiguration

ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml")

The above code requires that activiti.cfg.xml must have a bean of processEngineConfiguration

You can also use the following method to change the bean Name:

ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);

4 workflow engine creation

The workflow engine is equivalent to a facade interface. The process engine is created through the process engine configuration, and each service interface is created through the process engine.

4.1 default creation method

Fix the activiti.cfg.xml file name and path, and the activiti.cfg.xml file has the configuration of processEngineConfiguration. You can use the following code to create processEngine:

//Directly use the tool class ProcessEngines and use the configuration in activiti.cfg.xml under the classpath to create a processEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

4.2 general creation method

//Build ProcessEngineConfiguration first
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//Create a ProcessEngine through ProcessEngineConfiguration, and the database will be created
ProcessEngine processEngine = configuration.buildProcessEngine();

5 Servcie service interface

Service is a service interface provided by the workflow engine for workflow deployment, execution and management. We can use these interfaces to operate the data table corresponding to the service

5.1 Service creation method

Create Service through ProcessEngine

The method is as follows:

RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();

5.2 Service overview

service nameservice role
RepositoryServiceactiviti's resource management class
RuntimeServiceactiviti's process operation management class
TaskServiceactiviti's task management class
HistoryServiceactiviti's history management class
ManagerServiceactiviti's engine management class

Brief introduction:


Is the resource management class of activiti, which provides operations for managing and controlling process publishing packages and process definitions. The business process diagram designed with the workflow modeling tool needs to use this service to deploy the content of the process definition file to the computer.

In addition to deploying process definitions, you can also: query publishing packages and process definitions in the engine.

Pause or activate the release package, corresponding to all and specific process definitions. Pause means that they can no longer perform any operation, and activation is the corresponding reverse operation. Obtain a variety of resources, such as files contained in the distribution package, or flow charts automatically generated by the engine.

Get the pojo version of the process definition, which can be used to parse the process through java instead of xml.


Activiti's process operation management class. You can get a lot of information about process execution from this service class


Activiti's task management class. You can get the information of the task from this class.


Activiti's history management class can query historical information. When executing a process, the engine will save a lot of data (according to the configuration), such as the start time of the process instance, the participants of the task, the time to complete the task, the execution path of each process instance, and so on. This service mainly obtains these data through the query function.


The Activiti engine management class provides management and maintenance functions for the Activiti process engine. These functions are not used in workflow driven applications, but are mainly used for daily maintenance of the Activiti system.

Tags: Java Spring Boot IDE

Posted on Sat, 20 Nov 2021 10:40:30 -0500 by sdat1333