今天了解了一个新的东西–Activiti,虽然还没有真正把它的基本用法了解完,但是还是先记录一下它的部署过程。
Activity是以一种常见的工作流框架,它用来管理业务的流程,它覆盖了业务流程管理、工作流、服务协作等领域的一个开源的、灵活的、易扩展的可执行流程语言框架。
首先是pom.xml 导入包,这里使用Spring框架整合
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.15.1</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core-asl</artifactId>
<groupId>org.codehaus.jackson</groupId>
</exclusion>
<exclusion>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
</exclusion>
<exclusion>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
</exclusion>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.15.1</version>
</dependency>
然后导入配置文件spring-flow
<?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" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 数据源-->
<property name="dataSource" ref="dataSource" />
<!-- 事务管理 -->
<property name="transactionManager" ref="transactionManager" />
<!-- 更新数据库 如果没有则创建-->
<property name="databaseSchemaUpdate" value="true" />
<!-- 是否启动jobExecutor -->
<property name="jobExecutorActivate" value="true" />
<!-- 字体-->
<property name="labelFontName" value="宋体" />
<!-- 字体约束 -->
<property name="activityFontName" value="宋体" />
<property name="customFormTypes">
<list>
<bean class="org.activiti.explorer.form.UserFormType"/>
<bean class="org.activiti.explorer.form.ProcessDefinitionFormType"/>
<bean class="org.activiti.explorer.form.MonthFormType"/>
</list>
</property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean" destroy-method="destroy">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<!-- 工作流数据存储服务 -->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<!-- 工作流运行时服务 -->
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<!-- 工作流任务服务-->
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<!-- 工作流历史数据服务-->
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<!-- 工作流管理服务-->
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<!-- 工作流身份识别服务 -->
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
</beans>
先生成表文件,在使用测试类生创建数据引擎,创建完成后在数据库可以看到有二十张表,版本不一样,表数不一样
public class TestActivitiy {
ApplicationContext ioc = new ClassPathXmlApplicationContext("spring/spring-*.xml");
@Test
public void test01(){
//拿到数据引擎
ProcessEngine processEngine =(ProcessEngine) ioc.getBean("processEngine");
System.out.println("数据引擎"+processEngine);
}
}
接着就可以些流程控制了,你可能还需要有一个插件actiBPM可以让你用图形的方式画出工作流程
进入iead ->file->setting->Plugins搜索直接下载,下载完成后重启,防止出现中文乱码问题(直接配了)在idea安装目录bin下 两个文件的尾部加入-Dfile.encoding=UTF-8
在src/main/resources下面新建一个BPMN文件 新建之后页面会变成如下图所示这样,中间是画布,右边是一些元素,左边是每个元素的一些详细信息,直接拖拽右边的元素就可以画流程了。
idea中如果想看到BPMN文件对应的xml文件,可以将它复制一份后更改后缀名.xml将行了,如果想要将你设计好的流程转化为图片,可以执行下面操作
点击上面导航栏,绿色小箭头保存即可。
然后就是执行你构建的流程了。
然后就在数据表中生成插入一些数据(不懂),可以参考网上大牛的视频或博客。
再记录两个小异常:
- 执行文件要执行.bpmn 文件,虽然.xml也可以但是数据库表中的数据只有部分数据插入,act_re-procdef表没有数据
- 还有一个就是执行期间有异常,说是Usertask必须有class或expression属性,其实就是你在事件中加了监听器,虽然第一次在画流程图的时候自己并没有加,不知道怎么就加上了。