Activiti 基础

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_23597573/article/details/79946278

Activiti的使用

结构最简单的工作流流程

先使用eclipse上的Activiti插件生成相应的bpmn文件和png格式图片,如下图所示:

bpmn文件
png图片

配置文件 activiti.cfg.xml
<?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">

    <!-- setting business engine create param -->
    <bean id = "processEngineConfiguration" class = "org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="jdbcUrl" value = "jdbc:mysql://localhost:3306/permit?useUnicode=true&amp;characterEncoding=utf8" />    
        <property name="jdbcDriver" value = "com.mysql.jdbc.Driver" />    
        <property name="jdbcUsername" value = "root" />    
        <property name="jdbcPassword" value = "root" />    

        <property name="databaseSchemaUpdate" value = "true" />
    </bean>
</beans>

这里写图片描述

测试类:
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;

public class Test {
    public static void main(String[] args) {
        String deploymentId = "";
        String name = "";
        ProcessEngine processEngine = null;
        RepositoryService repositoryService  = null;
        Deployment deployment = null;
        ProcessDefinition singleResult  = null;
        ProcessInstance processInstance = null;


        //getDefaultProcessEngine 可以获取到默认的配置文件 activiti.cfg.xml
        processEngine = ProcessEngines.getDefaultProcessEngine();

        // repositoryService 指process 的bpmn和png两个文件
        repositoryService = processEngine.getRepositoryService();
        // DeploymentBuilder   定义 process deployment 相关参数
        deployment = repositoryService.createDeployment().name("Leave Process")
                .addClasspathResource("diagrams/LeaveProcess.bpmn")
                .addClasspathResource("diagrams/LeaveProcess.png").deploy();
        //deployment.getId()  可以获取到Activity生成的表 act_ge_bytearray中DEPLOYMENT_ID_值
        System.out.println("------deployment id:" + deployment.getId() + ",deployment name: " + deployment.getName());

        //ProcessDefinition是一个流程定义类,可以从这里获取一些资源文件
        singleResult = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
        //ProcessInstance 代表流程定义的执行实例,使用startProcessInstanceById 来查询
        deploymentId = singleResult.getId();
        System.out.println("singleResult.getId():"+deploymentId+",singleResult.getDeploymentId():"+singleResult.getDeploymentId());
        processInstance = processEngine.getRuntimeService().startProcessInstanceById(deploymentId);

        //使用startProcessInstanceByKey 来查询
        name = singleResult.getKey();
        System.out.println("singleResult.getKey(): "+name);
        processInstance = processEngine.getRuntimeService().startProcessInstanceByKey(name);
        System.out.println("------processInstance id: "+processInstance.getId()+",activiti id: "+processInstance.getActivityId());
    }
}
运行结果如下:

这里写图片描述

数据库相关数据:

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

以下23张表都是Activiti帮忙生成:

这里写图片描述

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页