preface

Workflow in our daily work can be said to be quite popular, especially in the enterprise internal management system, such as attendance, finance, contract and other systems is inseparable from it. In the next few articles, we will understand and learn how to use Activiti in enterprise development. Many online tutorials are scattered, so xiaobian prepared four articles, respectively introduction, basic, advanced, combat. As long as you master the use of Activiti in company development is not a problem at all. Because version 5.22 in Activiti5 is the most commonly used version by most enterprises, this tutorial is also explained using this version. The latest version has been upgraded to version 7.0, and we will learn some changes and usage of version 7.0 later.

I. Preparation for development

Activiti5 is a business process management (BPM) framework released by Alfresco on May 17, 2010, so our flow chart needs a tool to draw actiBPM. However, the latest version IDEA2020.3 is not compatible and cannot be installed. You can use other plug-ins. I installed the STS (Spring Tools 4 for Eclipse) development tool, which is specially used to operate Activiti5.

1. Install STS

2. Install the actiBPM plug-in

Ii. Development steps

1. Introduce the POM.xml dependency

<? 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.51.</version>
		<relativePath/>
	</parent>
	
	<groupId>com.dt</groupId>
	<artifactId>stsboot</artifactId>
	<version>0.01.-snapshot </version> <packaging>jar</packaging> <name> STsboot </name> <description>Activiti approval process </description> <properties>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<activiti.version>5.22. 0</activiti.version> </properties> <dependencies> <! -- Spring Web --> <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> <! --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <! Alibaba </groupId> <artifactId>druid</artifactId> <version>1.1. 5</version> </dependency> <! <dependency> <groupId>org.mybatis.spring. Boot </groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.32.</version> </dependency> <! --> <dependency> <groupId>org. Activiti </groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>${activiti.version}</version> </dependency> <! Activiti </groupId> <artifactId> Activiti </groupId> <artifactId> <version>${activiti.version}</version> </dependency> <! <dependency> <groupId>org. Activiti </groupId> <artifactId> Activiti -modeler</artifactId> <version>${activiti.version}</version> </dependency> <! Slf4j </groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <! <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional>
		</dependency>
		
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

Copy the code

2. Configure application.yml

server:
  port: 8081

spring:
  datasource:
    # Use Alibaba's Druid data source
    url: JDBC: mysql: / / 127.0.0.1:3306 / dtactiviti? useUnicode=true&characterEncoding=utf-8
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
      
  # Activiti configuration
  activiti:
    #1.flase: default value. When Activiti starts, it compares versions saved in database tables and throws an exception if there are no tables or versions do not match
    #2.true: Activiti updates all tables in the database. If the table does not exist, it is created automatically
    #3. Create_drop: Create tables when Activiti is started and drop tables when activiti is shut down (you must manually shut down the engine to drop tables)
    #4. Drop-create: Drop old tables when Activiti starts and then create new tables (no need to manually shut down the engine)
    database-schema-update: true

    The configurable history levels include None, Activity, Audit, and full
    # None: No historical data is saved, so this is most efficient during process execution.
    # Activity: A level higher than None saves the process instance and process behavior. Other data is not saved.
    #audit: All process tasks and their properties are saved in addition to the data stored at the activity level. Audit is the default value for history.
    #full: The highest level of historical data saving, in addition to audit level data, will save all other process related details data, including some process parameters, etc.
    history-level: full
    
    By default, check the processes folder in Resources
    check-process-definitions: false

# MyBatis configuration
mybatis:
  mapper-locations: classpath:mappers/*Mapper.xml
  type-aliases-package: com.example.demo.pojo
  configuration:
    map-underscore-to-camel-case: true
Copy the code

3. Start the main program

@SpringBootApplication
public class StsbootApplication {

	public static void main(String[] args) { SpringApplication.run(StsbootApplication.class, args); }}Copy the code

4. Startup error reported

Could not find class [org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration]
Copy the code

Since Activiti uses Security for user authorization, Acitivi-Rest is integrated with Spring-Security, which means you need to use Activiti with the Security framework.

However, our project does not intend to use Security for user authentication and authorization. Assuming we are using Shiro framework, how can we exclude Security?

1.1 Startup Class configuration excludes Security

@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
Copy the code

1.2 Pom.xml dependency excludes Security

<! Activiti </groupId> <artifactId> Activiti </groupId> <artifactId> <version>${activiti.version}</version> <exclusions> <exclusion> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> </exclusion> <exclusion> <groupId>org.springframework.security</groupId>  <artifactId>spring-security-crypto</artifactId> </exclusion> <exclusion> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> </exclusion> </exclusions> </dependency> <! <dependency> <groupId>org. Activiti </groupId> <artifactId> Activiti -modeler</artifactId> <version>${activiti.version}</version> <exclusions> <exclusion> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> </exclusion> <exclusion> <groupId>org.springframework.security</groupId>  <artifactId>spring-security-crypto</artifactId> </exclusion> <exclusion> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> </exclusion> </exclusions> </dependency>Copy the code

Restart, error again, error as follows:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Table 'dtactiviti.act_ge_property' doesn't exist
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectProperty-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_GE_PROPERTY where NAME_ = ?
Copy the code

Mysql uses schema to identify library names instead of categories, so mysql scans all libraries to find tables. If there is a table with the same name in another library, Activiti thinks it has found it, which essentially doesn’t exist in the current database.

1.3application.yml Sets MySQL connection parameters

nullCatalogMeansCurrent=true
Copy the code

NullCatalogMeansCurrent =true nullCatalogMeansCurrent=true nullCatalogMeansCurrent=true nullCatalogMeansCurrent=true nullCatalogMeansCurrent=true NullCatalogMeansCurrent =true is required.

Then start again and look carefully at the console print:

Our SpringBoot integration with Activiti was successful and 25 tables were successfully generated.

Ok, to this we completed the integration, the following we know 25 table structure, it is very important, only the table structure familiar, after the coding business logic you can understand, many beginners do not know these tables which is what, so feel this thing is difficult to learn.

Three, know 25 tables

There are too many tables here, xiaobian recommend an official organized document address, we can go here to consult.

www.devdoc.cn/activiti-ta…

conclusion

SpringBoot integration Activiti5.22.0, the beginning of the end, in fact, is our preparation, from this article, we know that we need to master a lot of Activiti, we need to get down and taste slowly, the next chapter we prepare the basic chapter, including process deployment, definition, tasks and other business operations.

Stay up late dry goods, creation is not easy, move small hands point praise !!!! Behind will continue to output more dry goods to you, like please pay attention to xiaobian CSDN: blog.csdn.net/qq_41107231 and nuggets: juejin.cn/user/394024…