1, Foreword
The purpose of this chapter is to initially build the Activiti process engine, to initially familiarize you with how to build an Activiti project, how to build the project, and to complete the preliminary study of the Activiti workflow. If you want to advance, you can read the following tutorials. This article will Gradually familiarize everyone with the advanced functions of Activiti.
2, Environment configuration
JDK version: 1.8 (1.6+ is enough)
maven version: 3.3.9+
Database ORM: MyBatis-plus
Transaction management: MyBatis mechanism/Spring transaction control
Database type: MySQL
Integrated interface: SOAP, Mule, RESTful
Internal service communication: API calls between Services
Framework usage: Springboot + MyBatis-Mybaties-plus
3, project construction
(1) POM file configuration
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.17</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.demo</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Process Engine</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <mysql.connector.version>8.0.22</mysql.connector.version> <mybatis.version>3.4.3.1</mybatis.version> <fastjson.version>1.2.79</fastjson.version> <activiti-dependencies.version>7.0.56</activiti-dependencies.version> </properties> <dependencies> <!-- springBoot component --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- mybatis component --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.connector.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatis.version}</version> </dependency> <!-- activiti component --> <dependency> <groupId>org.activiti.dependencies</groupId> <artifactId>activiti-dependencies</artifactId> <version>${activiti-dependencies.version}</version> <scope>import</scope> <type>pom</type> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <version>${activiti-dependencies.version}</version> </dependency> <!-- Other components --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> </dependencies> <repositories> <repository> <id>alfresco</id> <name>Activiti Releases</name> <url>https://artifacts.alfresco.com/nexus/content/repositories/activiti-releases/</url> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>
(2) application.yml configuration
# Service configuration server: display-name: myActiviti port: 8081 spring: application: name: demo #Configure data source information datasource: # Configure connection database information driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/catch?useUnicode=true & amp;characterEncoding=utf8 & amp;zeroDateTimeBehavior=convertToNull & amp;useSSL=false & amp;serverTimezone=GMT+8 & amp;rewriteBatchedStatements=true username: root password: 123456 xa: properties: pinGlobalTxToPhysicalConnection: true useServerPrepStmts: true thymeleaf: mode: HTML encoding: utf-8 # Disable caching cache: false mvc: # Static resource path static-path-pattern: /static/** Activiti: # Automatically create tables database-schema: ACTIVITI database-schema-update: true history-level: full db-history-used: true
(3)resource/static/**.yml
spring: Activiti: # After setting the asyncExecutorEnabled attribute to true, it will replace those old Job executors. async-executor-enabled: false job-executor-activate: false # asyncExecutorActivate instructs activiti to activate AsyncExecutor when the process engine starts, asynchronously async-executor-activate: # Verify process files. By default, the process files in the processes folder under resources are verified. check-process-definitions: # Use custom mybatis-mapper custom-mybatis-mappers: custom-mybatis-xmlmappers: #Data source specification database-schema: # Table creation rules # flase: Default value. When activiti starts, it will compare the versions saved in the database table. If there is no table or the version does not match, an exception will be thrown. # true: activiti will update all tables in the database. If the table does not exist, it is automatically created. # create_drop: Create the table when Activiti starts and delete the table when it is shut down (the engine must be shut down manually to delete the table). # drop-create: Delete the original old table when activiti starts, and then create a new table (no need to shut down the engine manually) database-schema-update: false # Check whether the history table exists db-history-used: false # Check whether the identity information table exists db-identity-used: false # Process deployment name deployment-name: # Record history level. Configurable history levels include none, activity, audit, and all. history-level: # spring jpa use jpa-enabled: false # Email sending service configuration mail-server-default-from: mail-server-host: mail-server-password: mail-server-port: mail-server-use-ssl: mail-server-use-tls: mail-server-user-name: # Customize process file location process-definition-location-prefix: process-definition-location-suffixes: #activiti rest configuration rest-api-enabled: false rest-api-mapping: rest-api-servlet-name:
(4)Download plug-in
ActiBPM can be selected for Idea2019 and 2020 versions
For versions after Idea2021, you can use Activiti BPMN visualizer, which will be more convenient to use.
After downloading, right-click to create a new one
After creating a new one, right-click on the xml and click view BPMN
(5) Create a new flow chart
Create a new start node
Intermediate approval node
end node
Save PNG
(6)Write test cases
@SpringBootTest class DemoApplicationTests { static ProcessEngine processEngine = null; @BeforeEach void test() { /** * Initialize the process engine object, and 25 data tables will be created according to the configuration (indexes and foreign keys are created) */ processEngine = ProcessEngines.getDefaultProcessEngine(); } @Test public void insert() { // 2. Get the RepositoryService instance RepositoryService repositoryService = processEngine.getRepositoryService(); // 3. Use RepositoryService for deployment, define a process name, and deploy bpmn and png to the database. Deployment deployment = repositoryService.createDeployment() // Create a deployment process .name("Leave Application Process") // Name the deployment process .addClasspathResource("bpmn/vacation.bpmn20.xml") //Add resource files under the classpath .addClasspathResource("bpmn/diagram.png") .deploy(); // Execute process deployment // 4. Output deployment information System.out.println("Process deployment id: " + deployment.getId()); System.out.println("Process deployment name: " + deployment.getName()); } }