springboot整合activiti工作流

一、前言

Spring Boot基于“習(xí)慣優(yōu)于配置”的原則,為大量第三方的庫提供自動配置的功能。由Spring專家Josh Long主導(dǎo)開發(fā)的spring-boot-starters為我們在Spring Boot下使用Activiti做了自動配置。 其中主要自動配置包括: * 自動創(chuàng)建Activiti ProcessEngine的Bean; * 所有的Activiti Service都自動注冊為Spring的Bean; * 創(chuàng)建一個Spring Job Executor; * 自動掃描并部署位于src/main/resources/processes目錄下的流程處理文件。



二、開始

1.maven添加activiti的依賴


<dependency>


<groupId>org.activiti</groupId>


<artifactId>activiti-spring-boot-starter-basic</artifactId>


<version>5.21.0</version>


</dependency>



2.創(chuàng)建流程圖文件

? ? 2.1在resources下建立processes目錄

? ? 2.2在processes目錄下將bpmn、bpmn.xml或bpmn20.xml等后綴的文件(activiti-explorer流程圖導(dǎo)出文件)放入其中? ?

? ?


? ? ? ?三、編寫測試代碼

package com.real2tech.cloudreform.service;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;import java.util.HashMap;import java.util.Map;@Servicepublic class ActivityService { private final Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; public boolean startActivity() { logger.info("工作流啟動...."); Mapmap = new HashMap();

? ? ? ? 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("工作流結(jié)束....");

? ? ? ? return false;

? ? }

}

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ?

? ? ? ? ? ?

? ? ? ?

? ? ? ? ? ?

? ?

? ? ? ?

? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?


? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?



? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容