Activity 学习笔记
activiti是什么?
业务流程管理(BPM)框架,开发人员可直接通过手绘流程图的方式,实现业务流程的控制。
使用步骤:
- 部署acitiviti:
- 编辑定义流程(BPMN):
- 部署流程定义:
- 启动流程实例:
- 用户查询代办事项(Task):
- 用户办理完成任务:
- 流程结束:
表
- 25张表:act开头
- re:静态数据和资源表
- ru:运行过程中产生的数据
- ge:通用数据
核心服务引擎:processEngine
- RuntimeService:
- TaskService:
- HistoryService:
- RepositoryService:
- ProcessInstance:
- ManagementService:
创建BPMN:
可以使用activiti-explorer编辑流程文件,或IDEA、Eclipse插件编辑。
可以参考这篇博文:Activiti介绍与官方demo使用(activiti-explorer)与25表的解析
单个部署流程定义,文件上传方式:
- 创建ProcessEngine实例
- 获取RepositoryService实例
- 使用RepositoryService进行部署,上传资源
- 得到Deployments实例,查看部署信息
- 创建ProcessEngine实例
- 获取RuntimeService实例
- 获取ProcessInstance实例
- 发起流程:
- 1.act_re_deployment: 记录部署操作
- 2.act_re_procdef:流程定义信息
- 3.act_ge_bytearray:资源文件保存
两种流程部署方式:
1.单个部署
2.zip压缩文件上传部署
Activiti整合Spring
创建MAVEN工程
导入依赖
以下为本人测试时引入依赖,可以参考:- <?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.example</groupId>
- <artifactId>activitiDemo</artifactId>
- <version>1.0-SNAPSHOT</version>
- <properties>
- <maven.compiler.source>8</maven.compiler.source>
- <maven.compiler.target>8</maven.compiler.target>
- <activiti.version>7.0.0.Beta1</activiti.version>
- <slf4j.version>1.7.7</slf4j.version>
- <log4j.version>1.2.12</log4j.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-engine</artifactId>
- <version>7.0.0.Beta1</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-spring</artifactId>
- <version>${activiti.version}</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-bpmn-model</artifactId>
- <version>${activiti.version}</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-bpmn-converter</artifactId>
- <version>${activiti.version}</version>
- </dependency>
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-bpmn-layout</artifactId>
- <version>${activiti.version}</version>
- </dependency>
- <dependency>
- <groupId>org.activiti.cloud</groupId>
- <artifactId>activiti-cloud-services-api</artifactId>
- <version>${activiti.version}</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>8.0.21</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>3.4.6</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>
- <scope>test</scope>
- </dependency>
- <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>
- </project>
复制代码 日志信息配置文件
日志信息配置文件log4j.properties- log4j.rootCategory=debug, CONSOLE, LOGFILE
- log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
- log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
- log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
- log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n
- log4j.appender.LOGFILE=org.apache.log4j.FileAppender
- log4j.appender.LOGFILE.file=E:/act/activiti.log
- log4j.appender.LOGFILE.Append=true
- log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
- log4j,appender.LOGFILE.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n
复制代码 Activiti引擎配置文件
Activiti引擎配置文件activiti.cfg.xml,配置数据连接信息。如果不指定默认使用H2数据库。这里配置使用mysql。- <?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" >
-
- <property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver"/>
-
- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC"/>
-
- <property name="jdbcUsername" value="root"/>
-
- <property name="jdbcPassword" value="123456"/>
-
- <property name="databaseSchemaUpdate" value="true"/>
- </bean>
- </beans>
复制代码 启动测试
编写测试类,使用引擎工具类ProcessEngines.getDefaultProcessEngine()启动;- public class ActivitiTest {
- @Test
- public void testCreateDbTable(){
- //需要使用activiti提供的工具类
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
- System.out.println("****processEngine is :****"+processEngine);
- }
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |