【工作流引擎】Activiti的使用01

news2024/9/28 11:11:16

基础配置

依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.gavin</groupId>
    <artifactId>activiti</artifactId>
    <version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.12</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.2</version>
    </dependency>
<!--    连接池-->
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-engine</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-spring</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-bpmn-model</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-bpmn-converter</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-json-converter</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>

    <dependency>
        <groupId>org.activiti</groupId>
        <artifactId>activiti-bpmn-layout</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>
    <dependency>
        <groupId>org.activiti.cloud</groupId>
        <artifactId>activiti-cloud-services-api</artifactId>
        <version>7.0.0.Beta1</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.27</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.5</version>
    </dependency>


</dependencies>

</project>

创建数据库表

创建工作表引擎需要的数据库表:
创建方式—使用processEngine 创建

这里需要配置所需的xml文件,该文件位置在resource文件夹下,而且文件名必须为activities.cfg.xml

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/contex
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
配置引擎配置信息--里面包含数据库的配置以及表更新策略
    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://172.21.114.22:3306/activiti"/>
        <property name="jdbcUsername" value="root"/>
        <property name="jdbcPassword" value="123456"/>
<!--        数据库表生成策略,如果存在则直接使用-->
        <property name="databaseSchemaUpdate" value="true"/>
     </bean>


</beans>

生成数据表

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.junit.Test;

public class ActTest {
    @Test
    public void Test01(){
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
        System.out.println(engine);

    }
}

表的作用

生成的25张表:
在这里插入图片描述

操作数据表

有了这么多表,我们需要去操作这些表,activiti已经封装好了一些操作的api;

在这里插入图片描述
上面得到的**service,之后可以通过这些service去操作数据表:
比如
在这里插入图片描述
但是在这之前我们要了解这些service是管理哪些表的;
repositoryService—>资源管理服务(带re的表)
runtimeService—>流程运行服务(带ru的表)
taskService—>任务管理服务
historyService—>历史管理服务
identityService—>用户管理服务
managementService—>引擎管理服务

以上是activiti初始化时候的一些知识;

工作流引擎创建

以上在运行时使用了默认的创建方式—>
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
这种方式需要指定 activiti.cfg.xml的文件名以及存放位置;
源码

public synchronized static void init() {
    if (!isInitialized()) {
      if (processEngines == null) {
        // Create new map to store process-engines if current map is
        // null
        processEngines = new HashMap<String, ProcessEngine>();
      }
      ClassLoader classLoader = ReflectUtil.getClassLoader();
      Enumeration<URL> resources = null;
      try {
        resources = classLoader.getResources("activiti.cfg.xml");
      } catch (IOException e) {
        throw new ActivitiIllegalArgumentException("problem retrieving activiti.cfg.xml resources on the classpath: " + System.getProperty("java.class.path"), e);
      }
      .............................下面的代码略.....................

此时配置文件activiti.cfg.xml中的bean 名称processEngineConfiguration
calss需要指定为org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration

另一种方式是手动指定配置文件的位置,然后创建
processEngine实例

//        配置文件自定义
        ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
        //这里可以对bean进行命名
        ProcessEngineConfiguration newBeanName = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml", "newBeanName");
        
        ProcessEngine processEngine = processEngineConfigurationFromResource.buildProcessEngine();
        ProcessEngine processEngine1 = newBeanName.buildProcessEngine();

小结:工作流引擎创建的方式
默认

 ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

可以自定义配置文件名和bean的名

ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
    ProcessEngine processEngine = processEngineConfigurationFromResource.buildProcessEngine();

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1073399.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Promise resolver undefined is not a function

错误的代码 function handlUsernameOrEmail(rules,value,){const regex /^([a-zA-Z0-9_-])([a-zA-Z0-9_-])(\.[a-zA-Z0-9_-]){1,2}$/;if(regex.test(value)){return new Promise().resolve(成功);}else {return new Promise().reject(失败);}// console.log(rules,rules,valu…

图文详解六十道Java并发

图文详解六十道Java并发 基础 1.并行跟并发有什么区别? 从操作系统的角度来看,线程是CPU分配的最小单位。 并行就是同一时刻,两个线程都在执行。这就要求有两个CPU去分别执行两个线程。并发就是同一时刻,只有一个执行,但是一个时间段内,两个线程都执行了。并发的实现依…

三、机器学习基础知识:Python常用机器学习库(Numpy第一部分)

文章目录 1、Numpy定义2、ndarray对象3、Numpy数据类型4、Numpy数组类型 1、Numpy定义 Numpy是Numberical Python的简称&#xff0c;是用来进行高性能计算与分析的基础包&#xff0c;是Python中重要的扩充库。它支持高维度数组与矩阵运算&#xff0c;也针对数组运算提供了大量…

gradle依赖导入,jar方式

新项目使用了gardle方式导入依赖&#xff0c;但是很不巧我都没有听过这个东西&#xff0c;然后就紧急的学了学&#xff0c;发现其实也听见的&#xff0c;然后准备动手试一下 问题 导入dm数据库驱动&#xff0c;换了好几种写法也不大行&#xff0c;然后发现我之前的项目也是使…

IDERA ER/Studio Data Professional 19.3.5 Crack

IDERA ER/Studio 数据架构师&#xff1f; 它能够从用户的单个界面创建和管理多个数据库平台的数据模型。信息建模者和架构师希望对与小型企业需求相关的不同数据高度做出反应。有些关键行动可能需要他们的关注。 特点&#xff1a; 构建数据模型作为增长周期的一部分。发现并记…

Redis的C客户端(hiredis库)使用

文章目录 1、Ubuntu安装redis服务端2、hiredis库的安装3、同步API接口的使用3.1、连接redis数据库redisConnect3.2、发送需要执行的命令redisCommand3.3、redisCommandArgv函数3.4、redisAppendCommand*函数支持管道命令3.5、释放资源3.6、同步连接代码 3.7、异步连接4、redis连…

Docker+jenkinsPipeline 运行实现python自动化测试

一、实现思路 在 Linux 服务器安装 docker创建 jenkins 容器jenkins 中创建 pipeline 项目根据自动化项目依赖包构建 python 镜像(构建自动化 python 环境)运行新的 python 容器&#xff0c;执行 jenkins 从仓库中拉下来的自动化项目执行完成之后删除容器 二、环境准备 Lin…

centos7上 ytalk 命令找不到?yum没有ytalk的软件包

1.描述 [rootoomcserver ~]# yum search ytalk Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Repodata is over 2 weeks …

一文搞懂到底什么是元宇宙

一、背景 2021年&#xff0c;“元宇宙”是科技界的开端。 2021”元宇宙”这个词在Facebook更名后被点燃了&#xff0c;无疑是21世纪科技界最爆的起点。各式各样的定义、解读都出现了&#xff0c;有人说它是炒作&#xff0c;甚至是骗局&#xff0c;但也有人说它就是互联网的未…

公众号点击原文下载文件怎么设置

作为微信生态下的产品&#xff0c;公众号推文中添加外部超链接的能力&#xff0c;多年一直没有开放给广大的运营者&#xff0c;只有开通了微信支付的服务号&#xff0c;才能在公众号文章正文添加链接&#xff0c;对于经常在公众号分享课件资料或者需要添加各种申请表的运营者来…

信号采样基本概念 —— 7.数模转换(DAC ADC)

文章目录 数字转模拟&#xff08;DAC&#xff09;一个简单的数字转模拟方案 模拟转数字&#xff08;ADC&#xff09; 数字转模拟&#xff08;DAC&#xff09; 通常来说&#xff0c;我们在设备上存储的数据是以二进制进行传输的&#xff0c;但是当我们试图将数据传输到更远的地…

《深入理解计算机系统》(1):系统组成

一、系统硬件组成 1、控制器&#xff08;CPU&#xff09;&#xff1a;解释和执行内存中的指令 &#xff08;1&#xff09;、控制器 程序控制器&#xff1a;指令指针&#xff0c;指向主存中的机器语言指令&#xff0c;为一个字大小的存储设备或寄存器。 指令寄存器、指令译码器、…

基于docker+Keepalived+Haproxy高可用前后的分离技术

基于dockerKeepalivedHaproxy高可用前后端分离技术 架构图 服务名docker-ip地址docker-keepalived-vip-iphaproxy-01docker-ip自动分配 未指定ip192.168.31.252haproxy-02docker-ip自动分配 未指定ip192.168.31.253 安装haproxy 宿主机ip 192.168.31.254 宿主机keepalived虚…

k8s-9 ingress-nginx 特性

TLS加密 创建证书 测试 auth认证 创建认证文件 rewrite重定向 进入域名 会自动重定向hostname.html 示例二&#xff1a; 测试 后面必须跟westos 这个关键字 canary金丝雀发布 基于header灰度 场景&#xff1a;版本的升级迭代&#xff0c;比如一个service 升级到另…

react学习之---jsx转成虚拟dom的过程

jsx----经过Bebal编译返回可供React.createElement()可调用的对象—React.createElement调用后生成虚拟dom—diff算法—生成新的真实dom 经过babel编译&#xff1a; import {greet} from ‘./utils’; const App {greet(‘scott’)}; ReactDOM.render(App, document.getEl…

芯引擎·新力量 | 第五届浦东新区长三角集成电路技能邀请赛圆满落幕

9月27日&#xff0c; 2023年全国工业和信息化技术技能大赛上海选拔赛、上海职工职业技能系列赛暨第五届浦东新区长三角集成电路技能邀请赛汽车芯片设计竞赛及颁奖典礼在上海集成电路设计产业园举办&#xff0c;上海市经济和信息化委员会人事教育处处长黄春华&#xff0c;上海市…

ESP32网络开发实例-Web服务器控制GPIO

Web服务器控制GPIO 文章目录 Web服务器控制GPIO1、软件准备2、硬件准备3、代码实现本文将介绍如何Arduino IDE编程环境创建一个具有ESP32的独立web服务器,ESP32控制输出(两个LED)。可以通过作为本地网络上的浏览器的任何设备访问。下面将逐步介绍如何创建web服务器以及代码的…

【Redis】Redis的几个应用场景(string数据类型的应用)

Redis的几个应用场景 缓存功能 ⽐较典型的缓存使⽤场景&#xff0c;其中Redis作为缓冲层&#xff0c;MySQL作为存储层&#xff0c;绝⼤部分请求的数据都是从Redis中获取。由于Redis具有⽀撑⾼并发的特性&#xff0c;所以缓存通常能起到加速读写和降低后端压⼒的作⽤。 计数功能…

MS2400隔离式调制器可pin对pin兼容AD7400

MS2400是一款二阶Σ-Δ调制器&#xff0c;集成片上数字隔离器&#xff0c;能将模拟输入信号转换为高速1位码流。可pin对pin兼容AD7400&#xff0c;可兼容AMC1303。调制器对输入信号连续采样&#xff0c;无需外部采样保持电路。模拟信号输入满量程为320mV&#xff0c;转换后的数…