Activiti工作流的初步学习
2016-08-11 23:57
281 查看
第一个Activiti程序
流程小结
1.创建流程图
eclipse插件、手动编写xml
推荐使用eclipse插件的方式
插件安装方式参考:http://www.cnblogs.com/strinkbug/p/4876819.html
2. 上传流程图
创建仓库(Repository)来保存流程图
流程引擎( processEnginer)<-流程引擎的配置
3.部署流程图
RepositoryService加载流程图,然后部署流程图
4.启动流程
Class Person{
}
Person p=new Person();//创建一个实例
processInstance //流程实例
Runtime,通过运行服务(RuntimeService)得到流程实例
5.处理流程任务
任务task,通过任务服务(taskservice)去检索待处理的任务
流程引擎的配置如下:
流程图(实现一个简单的HelloWorld任务):
具体实现的代码如下:
结果:
流程小结
1.创建流程图
eclipse插件、手动编写xml
推荐使用eclipse插件的方式
插件安装方式参考:http://www.cnblogs.com/strinkbug/p/4876819.html
2. 上传流程图
创建仓库(Repository)来保存流程图
流程引擎( processEnginer)<-流程引擎的配置
3.部署流程图
RepositoryService加载流程图,然后部署流程图
4.启动流程
Class Person{
}
Person p=new Person();//创建一个实例
processInstance //流程实例
Runtime,通过运行服务(RuntimeService)得到流程实例
5.处理流程任务
任务task,通过任务服务(taskservice)去检索待处理的任务
流程引擎的配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="jdbcUrl" value="jdbc:h2:mem:activiti"></property> <property name="jdbcDriver" value="org.h2.Driver"></property> <property name="jdbcUsername" value="sa"></property> <property name="jdbcPassword" value=""></property> <property name="databaseSchemaUpdate" value="true"></property> </bean> </beans>本工程由于只是简单的学习,所以采用了H2DB
流程图(实现一个简单的HelloWorld任务):
<?xml version="1.0" encoding="UTF-8"?> <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/test"> <process id="myProcess" name="第一个流程图" isExecutable="true"> <startEvent id="startevent1" name="开始事件"></startEvent> <userTask id="usertask1" name="HelloWorld"></userTask> <endEvent id="endevent1" name="结束事件"></endEvent> <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow> <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess"> <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="170.0" y="200.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"> <omgdc:Bounds height="55.0" width="105.0" x="520.0" y="230.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="430.0" y="380.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="205.0" y="217.0"></omgdi:waypoint> <omgdi:waypoint x="572.0" y="230.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="572.0" y="285.0"></omgdi:waypoint> <omgdi:waypoint x="447.0" y="380.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
具体实现的代码如下:
package com.activiti; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; 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 Helloword { public static void main(String[] args) { //1.获取流程引擎配置 ProcessEngineConfiguration config=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("/config/activiti.cfg.xml"); //2.创建流程引擎 ProcessEngine engine=config.buildProcessEngine(); //3.获取RepositoryService RepositoryService repositoryService=engine.getRepositoryService(); //4.部署流程图 repositoryService.createDeployment().addClasspathResource("process/HelloWorld.bpmn20.xml").deploy(); //5.获取运行时服务 RuntimeService runtimeService=engine.getRuntimeService(); //6.获取流程实例 String processDefinitionKey="myProcess"; ProcessInstance instance=runtimeService.startProcessInstanceByKey(processDefinitionKey); System.out.println(instance.getId()); //7.获取TaskService TaskService taskService=engine.getTaskService(); //8.查询task Task task=taskService.createTaskQuery().singleResult(); System.out.println(task.getName()); } }
结果:
相关文章推荐
- 工作流Activiti的学习总结(一)Spring和Activiti的整合配置讲解
- 工作流Activiti的学习总结- 整合简单的一个流程
- Activiti工作流学习总结(一)
- Activiti工作流学习-----基于5.19.0版本(3)
- Activiti工作流学习-----基于5.19.0版本(1)
- 工作流Activiti的学习总结(四)Spring和Activiti的整合配置讲解
- Activiti工作流学习-----基于5.19.0版本(7)
- 工作流学习——Activiti流程实例、任务管理四步曲
- 学习Activiti工作流框架的API
- Activiti工作流学习-----基于5.19.0版本(5)
- 工作流Activiti的学习总结- 整合比较复杂的一个流程
- 《疯狂Workflow讲义——基于Activiti的工作流应用开发》学习笔记之一·环境搭建之编码问题
- Activiti学习笔记一 工作流基本概念
- activiti工作流学习链接
- 工作流学习——Activiti流程实例、任务管理四步曲
- 工作流Activiti的学习总结- 整合spring mvc
- 工作流Activiti的学习总结(一)安装条件以及各步骤的作用以及不同环境需要lib包
- 工作流学习——Activiti整体认识二步曲
- Activiti工作流学习(二)流程实例、执行对象、任务
- Activiti工作流学习-----基于5.19.0版本(6)