工作流activiti 6 学习笔记一 环境搭建
第一步:进入activiti官网:https://www.activiti.org/get-started, 下载版本6的示例包https://github.com/Activiti/Activiti/releases/download/activiti-6.0.0/activiti-6.0.0.zip。
第二步:启动eclipse,安装画流程图的插件
进入developer Guide https://www.activiti.org/userguide/,
按照示例安装插件https://www.activiti.org/userguide/#eclipseDesignerInstallation
-
*Name:*Activiti BPMN 2.0 designer
-
*Location:*http://activiti.org/designer/update/
第三步:创建一个普通的java项目,新建一个lib包和resources包
lib包内放入第一步下载的压缩包的wars目录的app.war,将WEB-INF/lib 下的jar包全部复制到项目的lib下,并添加到buildpath,复制WEB-INF/classes 目录下的log4j.properties 文件到项目的resources目录中。
在resources 目录下新建 activiti.cfg.xml 文件,复制以下内容:https://www.activiti.org/userguide/#configuration, 数据库连接用户名密码记得一起更换。
<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" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" /> <property name="jdbcDriver" value="org.h2.Driver" /> <property name="jdbcUsername" value="sa" /> <property name="jdbcPassword" value="" /> <property name="databaseSchemaUpdate" value="true" /> <property name="asyncExecutorActivate" value="false" /> <property name="mailServerHost" value="mail.my-corp.com" /> <property name="mailServerPort" value="5025" /> </bean> </beans>
整体项目结构如下:
创建一个请假流程,部署,启动,并审批完成
package org.scf.act;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
public class MyAct {
public static void main(String[] args) {
// ProcessEngineConfiguration enc = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// 初始化流程引擎
ProcessEngine en = ProcessEngines.getDefaultProcessEngine();
// 存储服务
RepositoryService rs = en.getRepositoryService();
// 运行时服务
RuntimeService runS = en.getRuntimeService();
// 任务服务
TaskService ts = en.getTaskService();
// 部署流程
rs.createDeployment().addClasspathResource("leave.bpmn").deploy();
// 启动流程
String processdefId = rs.getProcessDefinition("myProcess:1:4").getDeploymentId();
System.out.println(processdefId);
ProcessInstance pi = runS.startProcessInstanceById("myProcess:1:4");
Task task = ts.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).singleResult();
System.out.println("当前节点的名字是:"+task.getName());
ts.complete(task.getId());
System.out.println("流程是否结束"+pi.isEnded());
Task task1 = ts.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).singleResult();
System.out.println("当前节点的名字是:"+task1.getName());
ts.complete(task1.getId());
System.out.println("流程是否结束:"+pi.isEnded());
Task task2 = ts.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).singleResult();
System.out.println("当前节点的名字是:"+task2);
System.out.println("流程是否结束:"+pi.isEnded());
en.close();
System.exit(0);
}
}
- 点赞
- 收藏
- 关注作者
评论(0)