1. Construction and use of activiti7 workflow engine Maven project

Posted by BLottman on Thu, 20 Jan 2022 02:56:00 +0100


Activiti is only a workflow engine, not a complete workflow product or framework. When daily workflow is used, project development must be carried out on this basis. Activiti only supports process deployment - UML, process XML file deployment, process opening, approval and flow of approval nodes. It does not provide functions such as personnel, permissions and Web UI interface. When the project is used, an independent process service can be encapsulated through activiti, and the business system calls relevant interfaces to complete business approval.
In addition, some approval functions of Activiti have not provided API s that fully support direct operation for the approval habits of Chinese people, such as rejection, withdrawal, cancellation and other functions. There are many ways to realize these functions on the Internet. How to realize them is to further encapsulate the functions of Activiti in combination with the existing business requirements.
Here are mainly examples of how to use each single function of Activiti. In fact, complex business approval is further assembled from these small functions. Let's learn more about Activiti below.

1. Maven pure Activiti7 project construction (without Spring)

activiti itself is integrated into spring and internally relies on Spring+Mybatis

1.1 database

The default is H2 memory database. MySQL database is used here. There are 25 tables in total, which can be initialized with SQL. When the project starts, you can also initialize the table automatically through program configuration, and create the database here

Create DataBase activiti default character set utf8

1.2 dependence

<activiti.version>7.1.0.M6</activiti.version>   
<activiti.cloud.version>7.0.0.Beta1</activiti.cloud.version>
<mysql.version>8.0.20</mysql.version>  

<dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-engine</artifactId>
            <version>${activiti.version}</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring</artifactId>
            <version>${activiti.version}</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-bpmn-model</artifactId>
            <version>${activiti.version}</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-bpmn-converter</artifactId>
            <version>${activiti.version}</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-json-converter</artifactId>
            <version>${activiti.version}</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-bpmn-layout</artifactId>
            <version>${activiti.version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.0</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>

 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.25</version>
            <scope>test</scope>
        </dependency>
        

1.3,activiti.cfg.xml configuration

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

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
        <property name="username" value="root" />
        <property name="password" value="1234.com" />
    </bean>

    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource"/>
        <!--Automatically created activiti Table structure involved-->
        <property name="databaseSchemaUpdate" value="true" />
    </bean>

</beans>

1.4 code initialization table structure

@Slf4j
public class ActivitiTest {
    /**
     * When using Activiti for the first time, if the table structure is not initialized, you can initialize the table through this operation
     */
    @Test
    public void initTable(){
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        log.info(defaultProcessEngine.getName());
    }
}

2. Define workflow

activiti uses BPMN 2.0 to define the rule process. IDEA can edit the BPMN file by installing the activibpm plug-in. Multiple processes can be defined in one BPMN file. Sometimes multiple small function point processes are defined in one file (Multiple none start events are not supported). Generally, one file and one process manage myleave bpmn

2.1. bpmn files are exported into png pictures for subsequent business personnel to view

Copy the BPMN file to an XML file, right-click in Idea, and then click directories - > show BPMN 2.0 digester

Finally, export png pictures:

3. Process development process

  1. Define process
  2. Deployment process - to activiti server
  3. Start process
  4. The processor of each node reviews and submits the task
  5. End of process execution

Topics: Activiti