activiti7学习
Posted 想实习犯法吗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了activiti7学习相关的知识,希望对你有一定的参考价值。
文章目录
- 一.activiti
- 二.监听器
- 三.流程变量
- 四.组任务
- 五.网关
- 六.activiti和第三方整合
一.activiti
1.什么是activiti7
业务流程管理项目(BPM)
activiti,是一个工作流引擎,可以将业务系统中复杂的业务流程抽取出来,使用专门的建模语言BPMN2.0进行定义,业务流程按照预先定义的流程进行执行,实现了系统的流程由activiti进行管理,减少业务系统由于流程变更进行系统升级改造的工作量,从而提高系统健壮性。
2.activiti7所需要的安装环境
(1)所需jar包
1、activiti-engine-7.0.0.beta1.jar
2、activiti 依赖的 jar 包: mybatis、 alf4j、 log4j 等
3、activiti 依赖的 spring 包
4、mysql数据库驱动(数据库驱动可以更具自己所需而变动,详细参照activiti支持的数据库)
5、第三方数据连接池 dbcp
6、单元测试 Junit-4.12.jar(为了测试使用activiti)
(2)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)在resources文件夹下创建日志配置文件以及activiti所需配置文件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"
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连接池-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/activiti?serverTimezone=GMT&nullCatalogMeansCurrent=true"/>
<property name="username" value="root"/>
<property name="password" value="19980420"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!--在默认方式下,bean的id固定为processEngineConfiguration-->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!--配置数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!-- 配置数据库相关内容-->
<!-- <property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver"/>-->
<!-- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?serverTimezone=GMT&nullCatalogMeansCurrent=true"/>-->
<!-- <property name="jdbcUsername" value="root"/>-->
<!-- <property name="jdbcPassword" value="19980420"/>-->
<!-- activiti在创建数据库时的策略,为true时,若存在相应的表,则使用,若不存在则创建-->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
</beans>
日志配置文件
# 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=%dISO8601 %-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=%dISO8601 %-6r[%15.15t] %-5p %30.30c %x - %m\\n
3.Activiti数据库表的自动创建
第一次运行这个代码时自动创建
public class TestCreate
// 使用activiti提供的默认方法来创建数据库
@Test
public void testCreateDbTable()
//需要使用activiti的工具类ProcessEngines,使用方法getDefaultProcessEngine,
//getDefaultProcessEngine会默认读取从resources下的activiti.cfg.xml文件中
// 在创建processEngine时,就会创建数据库的表
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
System.out.println(engine);
@Test
public void test1()
//使用下面这种方式生成表的条件
//1.activiti配置文件名称必须为activiti.cfg.xml
//2.activiti.cfg.xml中bean的id必须为"processEngineConfiguration"
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
System.out.println(engine );
@Test
public void test2()
//1.创建ProcessEngineConfiguration对象
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//2.创建ProcessEngine对象
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
4.Activiti各表的意义
表分类 | 表名 | 解释 |
一般数据 | ||
[ACT_GE_BYTEARRAY] | 通用的流程定义和流程资源,例如bpmn对应的xml文件以及png文件 | |
[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] | 运行时变量表 |
5.创建流程引擎
(1)默认方法
//1.activiti配置文件名称必须为activiti.cfg.xml
//2.activiti.cfg.xml中bean的id必须为"processEngineConfiguration"
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
System.out.println(engine );
(2)自定义方法
配置文件名称可以自定义,bean的名称也可以自定义
//1.创建ProcessEngineConfiguration对象
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml",processEngineConfiguration);
//2.创建ProcessEngine对象
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
6.service服务接口
(1)service创建方式
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
RepositoryService repositoryService = processEngine.getRepositoryService();
(2)service总览
service名称 | service作用 |
RepositoryService | activiti资源管理类 |
HistoryService | activiti历史管理类 |
RunTimeService | activiti流程运行管理类 |
TaskService | activiti任务管理类 |
ManageService | activiti引擎管理类 |
7.流程定义
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.activiti.org/processdef">
<process id="evection_1" name="evection" isExecutable="true">
<startEvent id="_2" name="StartEvent"/>
<userTask activiti:assignee="zhangsan" activiti:exclusive="true" id="_3" name="创建出差申请"/>
<userTask activiti:assignee="jerry" activiti:exclusive="true" id="_4" name="经理审批"/>
<userTask activiti:assignee="jack" activiti:exclusive="true" id="_5" name="总经理审批"/>
<userTask activiti:assignee="rose" activiti:exclusive="true" id="_6" name="财务审批"/>
<endEvent id="_7" name="EndEvent"/>
<sequenceFlow id="_8" sourceRef="_2" targetRef="_3"/>
<sequenceFlow id="_9" sourceRef="_3" targetRef="_4"/>
<sequenceFlow id="_10" sourceRef="_4" targetRef="_5"/>
<sequenceFlow id="_11" sourceRef="_5" targetRef="_6"/>
<sequenceFlow id="_12" sourceRef="_6" targetRef="_7"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_evection">
<bpmndi:BPMNPlane bpmnElement="evection_1" id="BPMNPlane_evection">
</bpmndi:BPMNPlane>
activiti7学习