news 2026/2/1 11:48:53

Activiti7工作流(二)开发环境

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Activiti7工作流(二)开发环境

文章目录

    • 1、Activiti所需开发环境
    • 2、下载activiti7
    • 3、流程设计器IDEA下安装
    • 4、Activiti的数据库支持
    • 5、 在MySQL生成表
      • 5.1 创建数据库
      • 5.2 使用java代码生成表
    • 6、 表结构介绍
      • 6.1 表的命名规则和作用
      • 6.2 Activiti数据表介绍

1、Activiti所需开发环境

  • Jdk1.8或以上版本

  • Mysql 5及以上的版本

  • Tomcat8.5

  • IDEA

2、下载activiti7

Activiti下载地址:http://activiti.org/download.html ,Maven的依赖如下:

<dependencyManagement><dependencies><dependency><groupId>org.activiti</groupId><artifactId>activiti-dependencies</artifactId><version>7.0.0.Beta1</version><scope>import</scope><type>pom</type></dependency></dependencies></dependencyManagement>

3、流程设计器IDEA下安装

在IDEA的File菜单中找到子菜单”Settings”,后面我们再选择左侧的“plugins”菜单,如下图所示:

此时我们就可以搜索到actiBPM插件,它就是Activiti Designer的IDEA版本,我们点击Install安装。

4、Activiti的数据库支持

Activiti 在运行时需要数据库的支持,使用25张表,把流程定义节点内容读取到数据库表中,以供后续使用。

Activiti 支持的数据库

activiti 支持的数据库和版本如下:

数据库类型版本JDBC连接示例说明
h21.3.168jdbc:h2:tcp://localhost/activiti默认配置的数据库
mysql5.1.21jdbc:mysql://localhost:3306/activiti?autoReconnect=true使用 mysql-connector-java 驱动测试
oracle11.2.0.1.0jdbc:oracle:thin:@localhost:1521:xe
postgres8.1jdbc:postgresql://localhost:5432/activiti
db2DB2 10.1 using db2jcc4jdbc:db2://localhost:50000/activiti
mssql2008 using sqljdbc4jdbc:sqlserver://localhost:1433/activiti

5、 在MySQL生成表

5.1 创建数据库

创建 mysql 数据库 activiti (名字任意):

CREATEDATABASEactivitiDEFAULTCHARACTERSETutf8;

5.2 使用java代码生成表

  • 1) 创建 java 工程

使用idea 创建 java 的maven工程,取名:activiti01。

  • 2) 加入 maven 依赖的坐标(jar 包)

首先需要在 java 工程中加入 ProcessEngine 所需要的 jar 包,包括:

  1. activiti-engine-7.0.0.beta1.jar

  2. activiti 依赖的 jar 包: mybatis、 alf4j、 log4j 等

  3. activiti 依赖的 spring 包

  4. mysql数据库驱动

  5. 第三方数据连接池 dbcp

  6. 单元测试 Junit-4.12.jar

我们使用 maven 来实现项目的构建,所以应当导入这些 jar 所对应的坐标到 pom.xml 文件中。

完整的依赖内容如下:

<properties><slf4j.version>1.6.6</slf4j.version><log4j.version>1.2.12</log4j.version><activiti.version>7.0.0.Beta1</activiti.version></properties><dependencies><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><!-- bpmn 模型处理 --><dependency><groupId>org.activiti</groupId><artifactId>activiti-bpmn-model</artifactId><version>${activiti.version}</version></dependency><!-- bpmn 转换 --><dependency><groupId>org.activiti</groupId><artifactId>activiti-bpmn-converter</artifactId><version>${activiti.version}</version></dependency><!-- bpmn json数据转换 --><dependency><groupId>org.activiti</groupId><artifactId>activiti-json-converter</artifactId><version>${activiti.version}</version></dependency><!-- bpmn 布局 --><dependency><groupId>org.activiti</groupId><artifactId>activiti-bpmn-layout</artifactId><version>${activiti.version}</version></dependency><!-- activiti 云支持 --><dependency><groupId>org.activiti.cloud</groupId><artifactId>activiti-cloud-services-api</artifactId><version>${activiti.version}</version></dependency><!-- mysql驱动 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.40</version></dependency><!-- mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.4.5</version></dependency><!-- 链接池 --><dependency><groupId>commons-dbcp</groupId><artifactId>commons-dbcp</artifactId><version>1.4</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><!-- log start --><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>${log4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${slf4j.version}</version></dependency></dependencies>

3) 添加log4j日志配置

我们使用log4j日志包,可以对日志进行配置

在resources 下创建log4j.properties

# Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE debug info warn error fatal log4j.rootCategory=debug, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=f:\act\activiti.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n

4) 添加activiti配置文件

我们使用activiti提供的默认方式来创建mysql的表。

默认方式的要求是在 resources 下创建 activiti.cfg.xml 文件,注意:默认方式目录和文件名不能修改,因为activiti的源码中已经设置,到固定的目录读取固定文件名的文件。

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"></beans>

5) 在 activiti.cfg.xml 中进行配置

默认方式要在在activiti.cfg.xml中bean的名字叫processEngineConfiguration,名字不可修改

在这里有2中配置方式:一种是单独配置数据源,一种是不单独配置数据源

1、直接配置processEngineConfiguration

processEngineConfiguration 用来创建 ProcessEngine,在创建 ProcessEngine 时会执行数据库的操作。

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 默认id对应的值 为processEngineConfiguration --><!-- processEngine Activiti的流程引擎 --><beanid="processEngineConfiguration"class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"><propertyname="jdbcDriver"value="com.mysql.jdbc.Driver"/><propertyname="jdbcUrl"value="jdbc:mysql:///activiti"/><propertyname="jdbcUsername"value="root"/><propertyname="jdbcPassword"value="123456"/><!-- activiti数据库表处理策略 --><propertyname="databaseSchemaUpdate"value="true"/></bean></beans>

2、配置数据源后,在processEngineConfiguration 引用

首先配置数据源

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 这里可以使用 链接池 dbcp--><beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><propertyname="driverClassName"value="com.mysql.jdbc.Driver"/><propertyname="url"value="jdbc:mysql:///activiti"/><propertyname="username"value="root"/><propertyname="password"value="123456"/><propertyname="maxActive"value="3"/><propertyname="maxIdle"value="1"/></bean><beanid="processEngineConfiguration"class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"><!-- 引用数据源 上面已经设置好了--><propertyname="dataSource"ref="dataSource"/><!-- activiti数据库表处理策略 --><propertyname="databaseSchemaUpdate"value="true"/></bean></beans>

6) java类编写程序生成表

创建一个测试类,调用activiti的工具类,生成acitivti需要的数据库表。

直接使用activiti提供的工具类ProcessEngines,会默认读取classpath下的activiti.cfg.xml文件,读取其中的数据库配置,创建 ProcessEngine,在创建ProcessEngine 时会自动创建表。

代码如下:

packagecom.itheima.activiti01.test;importorg.activiti.engine.ProcessEngine;importorg.activiti.engine.ProcessEngineConfiguration;importorg.junit.Test;publicclassTestDemo{/** * 生成 activiti的数据库表 */@TestpublicvoidtestCreateDbTable(){//使用classpath下的activiti.cfg.xml中的配置创建processEngineProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();System.out.println(processEngine);}}

说明:

1、运行以上程序段即可完成 activiti 表创建,通过改变 activiti.cfg.xml 中databaseSchemaUpdate 参数的值执行不同的数据表处理策略。
2 、 上 边 的 方法 getDefaultProcessEngine方法在执行时,从activiti.cfg.xml 中找固定的名称 processEngineConfiguration 。

执行完成后我们查看数据库, 创建了 25 张表,结果如下:

6、 表结构介绍

6.1 表的命名规则和作用

Activiti 的表都以 ACT_ 开头。

第二部分是表示表的用途的两个字母标识。 用途也和服务的 API 对应。

  • ACT_RE :'RE’表示 repository。 这个前缀的表包含了流程定义和流程静态资源 (图片,规则,等等)。

  • ACT_RU:'RU’表示 runtime。 这些运行时的表,包含流程实例,任务,变量,异步任务,等运行中的数据。 Activiti 只在流程实例执行过程中保存这些数据, 在流程结束时就会删除这些记录。 这样运行时表可以一直很小速度很快。

  • ACT_HI:'HI’表示 history。 这些表包含历史数据,比如历史流程实例, 变量,任务等等。

  • ACT_GE : GE 表示 general。 通用数据, 用于不同场景下

6.2 Activiti数据表介绍

表分类表名解释
一般数据[ACT_GE_BYTEARRAY]通用的流程定义和流程资源
一般数据[ACT_GE_PROPERTY]系统相关属性
流程历史记录[ACT_HI_ACTINST]历史的流程实例
流程历史记录[ACT_HI_ATTACHMENT]历史的流程附件
流程历史记录[ACT_HI_COMMENT]历史的说明性信息
流程历史记录[ACT_HI_DETAIL]历史的流程运行中的细节信息
流程历史记录[ACT_HI_IDENTITYLINK]历史的流程运行过程中用户关系
流程历史记录[ACT_HI_PROCINST]历史的流程实例
流程历史记录[ACT_HI_TASKINST]历史的任务实例
流程历史记录[ACT_HI_VARINST]历史的流程运行中的变量信息
流程定义表[ACT_RE_DEPLOYMENT]部署单元信息
流程定义表[ACT_RE_MODEL]模型信息
流程定义表[ACT_RE_PROCDEF]已部署的流程定义
运行实例表[ACT_RU_EVENT_SUBSCR]运行时事件
运行实例表[ACT_RU_EXECUTION]运行时流程执行实例
运行实例表[ACT_RU_IDENTITYLINK]运行时用户关系信息,存储任务节点与参与者的相关信息
运行实例表[ACT_RU_JOB]运行时作业
运行实例表[ACT_RU_TASK]运行时任务
运行实例表[ACT_RU_VARIABLE]运行时变量表


“人的一生会经历很多痛苦,但回头想想,都是传奇”。


版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/1/31 2:21:57

NVIDIA Profile Inspector终极优化指南:解锁显卡隐藏性能

NVIDIA Profile Inspector终极优化指南&#xff1a;解锁显卡隐藏性能 【免费下载链接】nvidiaProfileInspector 项目地址: https://gitcode.com/gh_mirrors/nv/nvidiaProfileInspector 如何突破显卡性能瓶颈&#xff0c;让游戏体验更上一层楼&#xff1f;NVIDIA Profil…

作者头像 李华
网站建设 2026/1/31 17:26:15

LobeChat能否对接古籍数据库?中华传统文化智能问答系统

LobeChat能否对接古籍数据库&#xff1f;中华传统文化智能问答系统 在博物馆的互动展区&#xff0c;一个孩子指着展板上的古文问&#xff1a;“‘天下兴亡&#xff0c;匹夫有责’是谁说的&#xff1f;”旁边的父亲尝试用手机搜索&#xff0c;结果跳出来的答案五花八门——有人说…

作者头像 李华
网站建设 2026/1/31 17:10:24

微信多设备登录难题的终极解决方案

微信多设备登录难题的终极解决方案 【免费下载链接】WeChatPad 强制使用微信平板模式 项目地址: https://gitcode.com/gh_mirrors/we/WeChatPad 你是否曾经因为微信只能在一个设备上登录而感到困扰&#xff1f;当你需要在手机和平板之间切换使用时&#xff0c;不得不反复…

作者头像 李华
网站建设 2026/1/31 18:13:56

PlayCover深度解密:在Mac上畅享iOS应用的终极方案

PlayCover深度解密&#xff1a;在Mac上畅享iOS应用的终极方案 【免费下载链接】PlayCover Community fork of PlayCover 项目地址: https://gitcode.com/gh_mirrors/pl/PlayCover 还在为Apple Silicon Mac无法体验心仪iOS应用而烦恼&#xff1f;想要在大屏幕上享受移动应…

作者头像 李华
网站建设 2026/1/31 17:09:26

RGBD slam

GitHub - ydsf16/dre_slam: RGB-D Encoder SLAM for a Differential-Drive Robot in Dynamic Environments

作者头像 李华