spring boot和activiti的demo

2023-11-10

开发十年,就只剩下这套Java开发体系了 >>>   hot3.png

1、添加依赖

<dependency>
	<groupId>org.activiti</groupId>
	<artifactId>activiti-spring-boot-starter-basic</artifactId>
	<version>6.0.0</version>
</dependency>

2、配置数据库信息

    mysql数据库配置

server:
  port: 8080
spring:
  application:
    name: activiti
  datasource:
    url: jdbc:mysql://xxxx.x.x.x:3306/xxxx?characterEncoding=utf8&useSSL=true
    driver-class-name: com.mysql.jdbc.Driver #配置JDBC Driver
    username: xxx
    password: xxxx
  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        show_sql: true
        use_sql_comments: true
        format_sql: true

3、接口定义及实现

    接口ActivityService

public interface ActivityService {
	/**
	 * 工作流
	 * @return
	 */
	public boolean startActivity();

}

    实现ActivityServiceImpl

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("activityService")
public class ActivityServiceImpl implements ActivityService {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private TaskService taskService;

	@Override
	public boolean startActivity() {
		logger.info("工作流启动....");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("apply", "zhangsan");
		map.put("approve", "lisi");
		// 流程启动
		ExecutionEntity pi1 = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave2", map);
		
		String processId = pi1.getId();
		Task task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
		logger.info("task 第一步:{}", task);
		taskService.complete(task.getId(), map);// 完成第一步申请

		task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
		logger.info("task 第二步:{}", task);
		String taskId2 = task.getId();
		map.put("pass", false);
		taskService.complete(taskId2, map);// 驳回申请
		
		task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
		logger.info("task 第三步:{}", task);
		logger.info("工作流结束....");
		return false;
	}
}

4、创建bpmn文件

    在resources目录下新建文件夹:processes,并在processes创建一个新的bpmn文件

<?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="leave2" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="员工申请" activiti:assignee="${apply}"></userTask>
    <userTask id="usertask2" name="经理审批" activiti:assignee="${approve}"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <userTask id="usertask3" name="修改申请" activiti:assignee="${apply}"></userTask>
    <sequenceFlow id="flow6" sourceRef="usertask3" targetRef="usertask2"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="是否通过"></exclusiveGateway>
    <sequenceFlow id="flow7" sourceRef="usertask2" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow9" name="通过" sourceRef="exclusivegateway1" targetRef="endevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow10" name="不通过" sourceRef="exclusivegateway1" targetRef="usertask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_leave2">
    <bpmndi:BPMNPlane bpmnElement="leave2" id="BPMNPlane_leave2">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="60.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="170.0" y="80.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="80.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="690.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="190.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="580.0" y="87.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="95.0" y="107.0"></omgdi:waypoint>
        <omgdi:waypoint x="170.0" y="107.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="275.0" y="107.0"></omgdi:waypoint>
        <omgdi:waypoint x="390.0" y="107.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="442.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="442.0" y="135.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="495.0" y="107.0"></omgdi:waypoint>
        <omgdi:waypoint x="580.0" y="107.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
        <omgdi:waypoint x="620.0" y="107.0"></omgdi:waypoint>
        <omgdi:waypoint x="690.0" y="107.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="620.0" y="107.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
        <omgdi:waypoint x="600.0" y="127.0"></omgdi:waypoint>
        <omgdi:waypoint x="442.0" y="190.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="600.0" y="127.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

163407_2aSi_182501.png

5、测试类测试

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.spring.pro.ProviderApplication;
import com.spring.pro.service.ActivityService;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ProviderApplication.class)
public class ActivitiTest {

	@Resource(name = "activityService")
	private ActivityService activityService;

	@Test
	public void leaveProcess() {
		activityService.startActivity();
	}
}

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring boot和activiti的demo 的相关文章

随机推荐

  • Java - Maven项目打包成jar给第三方使用(带依赖打包)

    打包成jar 引入这个jar 安装到本地仓库 直接指定jar包的位置 由于我们写项目的时候 有的时候并不是一个独立项目 而是作为一个第三方类库来提供服务的存在 用来给别的项目引入作为某个功能的封装 打包成jar 解决方案主要是从pom xm
  • Android studio 向项目里倒入model

    第一步 选择对应的model 倒入 第二步 完成第一步后 在项目列表里出现倒入的model 修改倒入的model的build gradle 1 如果有 apply plugin com android application 改为 appl
  • Android 7.1 GUI系统-surfaceflinger(四)

    surfaceflinger的启动 Android P 图形显示系统 https www jianshu com u f92447ae8445 Android GUI系统之SurfaceFlinger https blog csdn net
  • 使用libcurl下载文件小例

    libcurl是一个很强大的开源网络处理库 支持包括HTTP HTTPS FTP 一系列网络协议 用它来进行HTTP的get post 或者下载文件更是小菜一碟 chrome内核都用到了它 本文主要讲解一个使用curl下载文件的小例 首先是
  • 数据库的导入导出及授权

    目录 数据库导出 数据库导入 数据库授权 1 忘记root密码 2 创建表时 colume使用的时 mysql 保留字导致报错 数据库导出 1 导出数据库为bname的表结构 其中用户名为root 密码为dbpasswd 生成的脚本名为db
  • 判断素数 C C++两个版本

    题目 输入一个数 判断是否是素数 C代码 include
  • Midjourney2023下载使用详细操作方法教程

    手把手教你入门绘图超强的AI绘画程序Midjourney 用户只需要输入一段图片的文字描述 即可生成精美的绘画 下面是Midjourney注册和使用的方法 第一步 先注册一个Discord账号https discord gg 注册的时候要人
  • 第三十四章、PyQt中的输入部件:QComboBox组合框功能详解

    专栏 Python基础教程目录 专栏 使用PyQt开发图形界面Python应用 专栏 PyQt入门学习 老猿Python博文目录 一 概述 Designer中输入工具部件中的Combo Box组合框与其他可视化工具组合框功能相同 组合了按钮
  • 《QDebug 2023年1月》

    一 Qt Widgets 问题交流 二 Qt Quick 问题交流 三 其他 1 QScreen grabWindow 截屏 如果没有指定范围 默认是截取对应屏幕的区域 QScreen文档https doc qt io qt 5 15 qs
  • 在控制台打印1000以内的所有素数(质数)

    素数 质数 的定义 质数是指在大于1的自然数中 除了1和它本身以外不再有其他因数的自然数 编程思路 根据定义可以知道 代码应该包括两个循环 外层循环用于遍历范围内的每一个数 可以定义为i 内存循环则用来遍历由2至小于i的数 此处在遍历1和i
  • 挂马方式研究、挂马检测技术研究

    1 挂马定义 所谓的挂马 就是黑客通过各种手段 包括SQL注入 网站敏感文件扫描 服务器漏洞 网站程序0day 等各种方法获得网站管理员账号 然后登陆网站后台 通过数据库 备份 恢复 或者上传漏洞获得一个webshell 利用获得的webs
  • 目标检测算法之YOLOV2

    YOLOV2论文对v1中许多地方都进行了相关的改进和提升 其将骨干网络也进行了更换 不在使用v1的骨干网络 其v2骨干模型结构图如下 作者删去了骨干网络最下面的三层操作 接上了三个卷积核一个高维度特征与低维度特征的融合 并最终生成模型输出
  • 获取进程pid并添加数组,去重。

    var cmd process platform win32 tasklist ps aux var exec require child process exec var qqname qq Array prototype unique1
  • TV模型图像修复 matlab

    原lena 随手截的噪声图 合成的需要修复的图 修复后的图 没有处理边界 对于从来没有接触过图像修复的我来说 效果真是惊艳了 下面介绍运算步骤 和各项异性扩散类似 整个算法也是基于迭代的 迭代公式如下 其中Io代表当前处理的像素 Ip代表邻
  • Java代码规范检查插件调研及总结

    代码规范工具对比 代码规范工具是什么 大家应该都有过写完代码后review的情况 用于提高编码质量 尽早的发现问题 节约开发时间和成本 但review 这个过程往往要消耗 更多的开发资源 所以就出现 自动检测可能代码中存在的问题的工具 我们
  • nrichIP分析command tools(Sodan接口调用查询)

    nrichIP分析command tools 一 项目简介 nrich是一种命令行工具 可快速分析文件中的所有 IP 并查看哪些具有开放端口 漏洞 也可以从标准输入输入数据以在数据管道中使用 二 项目本地部署 1 项目地址 https gi
  • OpenCV样本训练经验

    从下述几篇文章中总结 OpenCV中Adaboost训练的经验总结 采用opencv cascadetrain进行训练的步骤及注意事项 使用opencv traincascade训练遇到的问题总汇 在讲下面内容时首先应先清楚一件事情 自己收
  • 微信营销最重要的是什么

    随着移动互联网的迅速发展 微信已经成为了企业进行营销的重要平台之一 然而 众多企业在微信上进行营销 不同的策略和方法层出不穷 那么 微信营销最重要的是什么呢 本文将深入探讨这个问题 揭示微信营销的核心要素 1 用户价值和体验 微信营销最重要
  • CSDN 添加目录及基本操作(保姆级教程)

    文章目录 1 步骤 1 步骤 1 点击发布 2 这里点击右上角的使用MD编辑器 3 界面介绍 最左边是编辑区 中间视图区 最右边是语法说明区 也就是直接引用区 4 目录操作 toc 文章名称 在使用完在使用完 toc 操作后 对应的我们复制
  • spring boot和activiti的demo

    开发十年 就只剩下这套Java开发体系了 gt gt gt 1 添加依赖