Activiti工作流的初步学习

第一个Activiti程序

流程小结

1.创建流程图
eclipse插件、手动编写xml
推荐使用eclipse插件的方式

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());
		
		
	}

}
结果:




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值