一溯泣、初識(shí)activiti
因最近項(xiàng)目需求需要運(yùn)用流程,選擇使用activiti流程框架,網(wǎng)上大多是springboot2.0以下版本和activiti6.0的整合锚烦,因項(xiàng)目已經(jīng)使用springboot2.0扩然,所以記錄整合activiti7的過程艘儒。
個(gè)人對activiti的印象:
1.activiti本身就是一個(gè)比較完整的應(yīng)用程序,它包含數(shù)據(jù)庫夫偶,API和前端界睁;**可獨(dú)立運(yùn)行,詳細(xì)可參考[activiti 6.0](https://www.activiti.org/get-started)的三個(gè)應(yīng)用activiti-admin.war兵拢,activiti-app.war翻斟,activiti-rest.war(不要問我為啥不說7.0的,是因?yàn)槲以诠倬W(wǎng)沒找到7.0的相關(guān)文檔说铃,6.0的反而非常全)
2.activiti只是流程框架访惜;**關(guān)于原有項(xiàng)目與activiti整合,現(xiàn)在大致的想法是使用activiti的接口腻扇,創(chuàng)建和管理流程债热,具體的內(nèi)容還是存在自己創(chuàng)建的數(shù)據(jù)庫中。
二幼苛、創(chuàng)建activiti數(shù)據(jù)庫
現(xiàn)在開始用窒篱,先跑起來再說:
2.1 pom.xml
springboot 版本:2.2.1.RELEASE
activiti 版本:7.1.0.M1
mysql 版本:5.1.30(很關(guān)鍵)
具體代碼:
<?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.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>activiti-demo2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>activiti-demo2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- <scope>runtime</scope>-->
<version>5.1.30</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.2 創(chuàng)建activiti.cfg.xml文件
在resources文件下創(chuàng)建activiti.cfg.xml
<?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">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="databaseType" value="mysql"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti"></property>
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUsername" value="root"></property>
<property name="jdbcPassword" value="123456"></property>
</bean>
</beans>
2.3 創(chuàng)建activiti數(shù)據(jù)庫
需要先在mysql數(shù)據(jù)庫中創(chuàng)建名為“activiti”的數(shù)據(jù)庫
2.4 創(chuàng)建main函數(shù)
package com.example.activitidemo2;
import org.activiti.engine.impl.db.DbSchemaCreate;
/**
* @Description: test
* @Author: zx
* @Time: 2019-11-20 09:25
**/
public class Test {
public static void main(String[] args) {
DbSchemaCreate.main(args);
}
}
運(yùn)行main函數(shù)
2.5 創(chuàng)建成功
數(shù)據(jù)庫表說明:
ACT_RE_*: RE表示repository(倉庫),存儲(chǔ)流程靜態(tài)資源舶沿,如流程模型文件等
ACT_RU_*: RU表示runtime(運(yùn)行時(shí))墙杯,存儲(chǔ)activiti運(yùn)行時(shí)產(chǎn)生的數(shù)據(jù),比如實(shí)例信息括荡,用戶任務(wù)信息高镐,job信息等,另外畸冲,當(dāng)流程結(jié)束后嫉髓,運(yùn)行時(shí)數(shù)據(jù)將會(huì)被刪除,以保證數(shù)據(jù)量盡可能少邑闲,保證性能岩喷。
ACT_ID_*: ID表示identity(認(rèn)證),存儲(chǔ)認(rèn)證信息监憎,比如用戶纱意,組等。
ACT_HI_*: HI表示history(歷史)鲸阔,存儲(chǔ)流程歷史數(shù)據(jù)偷霉,比如實(shí)例信息迄委,變量數(shù)據(jù)等。
ACT_GE_*: GE表示general(通用)类少,存儲(chǔ)通用數(shù)據(jù)叙身。
表只有25張,(activiti7沒有ID類的表硫狞,不影響整合信轿,本來也不想要identity部分)(activiti6是28張)
三、踩過的坑
3.1 Springboot和activiti版本問題
springboot2.0以上建議用activiti7.0以上残吩,不然可能會(huì)遇到很多版本問題财忽,activiti6出的時(shí)候springboot2.0還沒出。
3.2 mysql和activiti版本問題
生成數(shù)據(jù)庫表的時(shí)候一定不能用com.mysql.cj.jdbc.Driver驅(qū)動(dòng)泣侮,原因是activiti暫時(shí)只支持com.mysql.jdbc.Driver即彪,所以需要把mysql版本降低。
bug:
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2121)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2145)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
... 30 more
參考網(wǎng)站: