[2]工作流框架:支持MySQL的Flowable安装

Posted 朱清云的技术博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[2]工作流框架:支持MySQL的Flowable安装相关的知识,希望对你有一定的参考价值。

引言

上一个章节提到了如何在Tomcat里面启动Flowable,但是其默认的数据库是H2; 但是在实际的开发和部署过程中,我们是需要把其储存到mysql,PostgreSQL,Oracle等数据库中;
那么应该如何做呢?笔者就接着上个章节的文章,演示如何把数据库迁移到MySQL。

安装MySQL

安装MySQL的文章很多,就不在赘述。安装MySQL后创建一个名字为flowable的数据库;
字符集编码为utf-8, 此数据库没有任何的表

下载MySQL的驱动包

MySQL的驱动的Jar包,Maven的依赖配置:
mysql-connector-java-8.0.17.jar

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.17</version>
</dependency>

可以到下面的地址去下载:
https://search.maven.org/artifact/mysql/mysql-connector-java/8.0.17/jar

把MySQL的驱动包放入Flowable-rest和Flowable-ui依赖库

把上面下载下来的Jar包放入下面的路径:

  • flowable-rest 项目
    D:\\workflow-poc\\flowable\\apache-tomcat-windows-9.0.8\\webapps\\flowable-rest\\WEB-INF\\lib

  • flowable-ui 项目
    D:\\workflow-poc\\flowable\\apache-tomcat-windows-9.0.8\\webapps\\flowable-ui\\WEB-INF\\lib

修改Flowable-rest和Flowable-ui的配置

修改两个项目的properties文件的配置

  • flowable- 项目
    D:\\workflow-poc\\flowable\\apache-tomcat-windows-9.0.8\\webapps\\flowable-ui\\WEB-INF\\classes


修改flowable-default.properties文件,把h2的driver class和url的配置都注释掉;然后把
相应的mysql的注释打开,然后把你的用户名和密码改成你实际连接MySQL的flowable数据库用户名和密码;

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/flowable?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=password
  • flowable-rest 项目
    进入 D:\\workflow-poc\\flowable\\apache-tomcat-windows-9.0.8\\webapps\\flowable-rest\\WEB-INF\\classes 目录,打开flowable-default.properties文件

    和上面做同样的操作
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/flowable?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=password

启动Flowable,但是不成功

启动后,Flowable的日志显示,其会默认找不到相应的数据库表

java.sql.SQLSyntaxErrorException: Table 'flowable.act_ge_property' doesn't exist
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.17.jar:8.0.17]
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.17.jar:8.0.17]
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.17.jar:8.0.17]
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.17.jar:8.0.17]
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003) ~[mysql-connector-java-8.0.17.jar:8.0.17]
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.4.5.jar:?]
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.5.jar:?]
        at org.flowable.common.engine.impl.db.AbstractSqlScriptBasedDbSchemaManager.getProperty(AbstractSqlScriptBasedDbSchemaManager.java:191) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.common.engine.impl.db.ServiceSqlScriptBasedDbSchemaManager.getSchemaVersion(ServiceSqlScriptBasedDbSchemaManager.java:111) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.common.engine.impl.db.ServiceSqlScriptBasedDbSchemaManager.schemaUpdate(ServiceSqlScriptBasedDbSchemaManager.java:67) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.db.ProcessDbSchemaManager.schemaUpdate(ProcessDbSchemaManager.java:215) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:54) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:28) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:59) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:107) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:81) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:64) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:26) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:83) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57) ~[flowable-spring-common-6.6.0.jar:6.6.0]
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57) ~[flowable-spring-common-6.6.0.jar:6.6.0]
        at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) ~[flowable-engine-common-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:82) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:981) ~[flowable-engine-6.6.0.jar:6.6.0]
        at org.flowable.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:75) ~[flowable-spring-6.6.0.jar:6.6.0]

初始化MySQL的表

新建一个Maven项目,加入下面的两个依赖:

  <!--Flowable流程引擎-->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-engine</artifactId>
            <version>6.6.0</version>
        </dependency>
        <!--MySQL驱动,这里采用MySQL数据库,如果采用其它数据库,需要引入对应的依赖。-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>
	

新建一个Java的启动类:

package com.test.flowable;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;


public class FlowableDbCreationApplication 

	public static void main(String[] args) 
		//1、创建ProcessEngineConfiguration实例,该实例可以配置与调整流程引擎的设置
        ProcessEngineConfiguration cfg=new StandaloneProcessEngineConfiguration()
                //2、通常采用xml配置文件创建ProcessEngineConfiguration,这里直接采用代码的方式
                //3、配置数据库相关参数
                .setJdbcUrl("jdbc:mysql://localhost:3306/flowable?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2b8&nullCatalogMeansCurrent=true")
                .setJdbcUsername("root")
                .setJdbcPassword("password")
                .setJdbcDriver("com.mysql.jdbc.Driver")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        //4、初始化ProcessEngine流程引擎实例
        ProcessEngine processEngine=cfg.buildProcessEngine();
	



启动上面的类,其就会自动创建Flowable的34张表

ACT_RE_* :’ RE ’表示repository(存储)。RepositoryService接口操作的表。带此前缀的表包含的是静态信息,如,流程定义,流程的资源(图片,规则等)。
ACT_RU_* :’ RU ’表示runtime。这是运行时的表存储着流程变量,用户任务,变量,职责(job)等运行时的数据。flowable只存储实例执行期间的运行时数据,当流程实例结束时,将删除这些记录。这就保证了这些运行时的表小且快。
ACT_ID_* : ’ ID ’表示identity(组织机构)。这些表包含标识的信息,如用户,用户组,等等。
ACT_HI_* : ’ HI ’表示history。就是这些表包含着历史的相关数据,如结束的流程实例,变量,任务,等等。
ACT_GE_* : 普通数据,各种情况都使用的数据。

再次从Tomcat启动Flowable

启动后,发现其在原来的基础之上,又增加到87张表

act_adm_databasechangelog
act_adm_databasechangeloglock
act_adm_server_config
act_app_appdef
act_app_databasechangelog
act_app_databasechangeloglock
act_app_deployment
act_app_deployment_resource
act_cmmn_casedef
act_cmmn_databasechangelog
act_cmmn_databasechangeloglock
act_cmmn_deployment
act_cmmn_deployment_resource
act_cmmn_hi_case_inst
act_cmmn_hi_mil_inst
act_cmmn_hi_plan_item_inst
act_cmmn_ru_case_inst
act_cmmn_ru_mil_inst
act_cmmn_ru_plan_item_inst
act_cmmn_ru_sentry_part_inst
act_co_content_item
act_co_databasechangelog
act_co_databasechangeloglock
act_de_databasechangelog
act_de_databasechangeloglock
act_de_model
act_de_model_history
act_de_model_relation
act_dmn_databasechangelog
act_dmn_databasechangeloglock
act_dmn_decision
act_dmn_deployment
act_dmn_deployment_resource
act_dmn_hi_decision_execution
act_evt_log
act_fo_databasechangelog
act_fo_databasechangeloglock
act_fo_form_definition
act_fo_form_deployment
act_fo_form_instance
act_fo_form_resource
act_ge_bytearray
act_ge_property
act_hi_actinst
act_hi_attachment
act_hi_comment
act_hi_detail
act_hi_entitylink
act_hi_identitylink
act_hi_procinst
act_hi_taskinst
act_hi_tsk_log
act_hi_varinst
act_id_bytearray
act_id_group
act_id_info
act_id_membership
act_id_priv
act_id_priv_mapping
act_id_property
act_id_token
act_id_user
act_procdef_info
act_re_deployment
act_re_model
act_re_procdef
act_ru_actinst
act_ru_deadletter_job
act_ru_entitylink
act_ru_event_subscr
act_ru_execution
act_ru_external_job
act_ru_history_job
act_ru_identitylink
act_ru_job
act_ru_suspended_job
act_ru_task
act_ru_timer_job
act_ru_variable
flw_channel_definition
flw_ev_databasechangelog
flw_ev_databasechangeloglock
flw_event_definition
flw_event_deployment
flw_event_resource
flw_ru_batch
flw_ru_batch_part


启动成功!

打开Swaggr UI

http://127.0.0.1:8080/flowable-rest/docs/?url=specfile/process/flowable-swagger-process.json

可以看到其提供的API如下:

总结

这个章节把数据库从H2迁移到了MySQL数据库;并把Swagger的URL也找见了!

参考文献:

https://developer.aliyun.com/article/840426?spm=5176.21213303.J_6704733920.46.36f83edaxd5kLe&scm=20140722.S_community%40%40%E6%96%87%E7%AB%A0%40%40840426._.ID_community%40%40%E6%96%87%E7%AB%A0%40%40840426-RL_Flowable-OR_main-V_2-P0_13

以上是关于[2]工作流框架:支持MySQL的Flowable安装的主要内容,如果未能解决你的问题,请参考以下文章

全网最火的工作流框架Flowable完整教程--基本操作

[1]工作流框架:Flowable基本安装

全网最火的工作流框架Flowable完整教程-Flowable核心基础

若依框架,集成flowable工作流

全网最火的工作流框架Flowable完整教程-FlowableUI应用

Flowable 工作流引擎