名片式网站模板,wordpress健康主题,室内设计学校网站,wordpress 高级选项Spring Boot 项目集成camunda流程引擎
camunda地址
camunda中文地址 使用camunda开源工作流引擎有#xff1a;通过docker运行、使用springboot集成、部署camunda发行包、基于源代码编译运行等多种方式。 文本重点介绍如何在Spring Boot应用程序中如何集成Camunda Platform开…Spring Boot 项目集成camunda流程引擎
camunda地址
camunda中文地址 使用camunda开源工作流引擎有通过docker运行、使用springboot集成、部署camunda发行包、基于源代码编译运行等多种方式。 文本重点介绍如何在Spring Boot应用程序中如何集成Camunda Platform开源流程平台这也是项目中最为常见的一种使用方式。 在本教程中我们假设您熟悉 Java Web 应用程序开发和 Spring Boot 的基础知识。前提条件是您已经安装了 Eclipse/IDEA等Java开发工具和 Camunda Modeler流程设计器。 1.新建Spring Boot 项目集成camunda
首先让我们在您选择的 IDE 中设置您的第一个流程应用程序项目。
该项目需要 Java jdk8以上版本。我本地使用的JDK版本为8使用的开发工具IDEA2024。
1.1. 添加 Camunda 平台和 Spring Boot 依赖项
下一步包括为新项目设置 Maven 依赖项。需要将 Maven 依赖添加到项目的文件中。由于本示例要使用camunda流程引擎、web界面、Rest服务接口所以需要导入camunda-bpm-spring-boot-starter-rest、camunda-bpm-spring-boot-starter-webapp依赖包。我们在“依赖管理”部分添加了 Spring Boot BOM和camunda相关依赖这将自动将 camunda 引擎、rest服务接口和 Web 应用程序包含在应用程序中。
我们使用camunda7.19.0版本该版本支持jdk8和springboot2。camunda和springboot版本的依赖对应关系查看官方文档说明Spring Boot Version Compatibility | docs.camunda.org ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionartifactIdcamunda-demo/artifactIdnamecamunda-demo/namegroupIdcom.liuhm/groupIdversion1.0/versiondescriptionDemo project for Spring Boot/descriptionpropertiesjava.version1.8/java.versionspring-boot.version2.7.5/spring-boot.versioncamunda.spring-boot.version7.19.0/camunda.spring-boot.version/propertiesdependencyManagementdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion${spring-boot.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementdependenciesdependencygroupIdorg.camunda.bpm.springboot/groupIdartifactIdcamunda-bpm-spring-boot-starter-webapp/artifactIdversion${camunda.spring-boot.version}/version/dependencydependencygroupIdorg.camunda.bpm.springboot/groupIdartifactIdcamunda-bpm-spring-boot-starter-rest/artifactIdversion${camunda.spring-boot.version}/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-jdbc/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion5.1.47/version/dependencydependencygroupIdcom.sun.xml.bind/groupIdartifactIdjaxb-impl/artifactIdversion2.3.6/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.28/version/dependency/dependenciesbuildfinalName${project.artifactId}/finalNamepluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdversion${spring-boot.version}/version/plugin!--指定JDK编译版本 --plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdconfigurationsource1.8/sourcetarget1.8/targetencodingUTF-8/encoding/configuration/plugin/plugins/build/project1.2. 配置 Spring Boot 项目
在项目中src/main/resources新建application.yml
让我们在文件夹中创建一个包含以下内容的文件application.yml
默认在mysql数据库中创建了camundatest
spring:datasource:url: jdbc:mysql://192.168.0.154:3306/camundatest?characterEncodingUTF-8useUnicodetrueuseSSLfalsezeroDateTimeBehaviorconvertToNullserverTimezoneAsia/Shanghaiusername: rootpassword: 123456driver-class-name: com.mysql.jdbc.Drivercamunda:bpm:database:type: mysqlschema-update: true # 是否自动建表但我测试为true时创建表会出现因此还是改成false由手工建表。auto-deployment-enabled: false # 自动部署 resources 下的 bpmn文件admin-user:id: adminpassword: 123456
server:port: 8080
此配置将导致以下结果
将创建具有提供的密码和名字的管理员用户 admin/123456。认使用mysql数据库启动时自动创建数据库。
1.3. 编写Spring Boot启动类
接下来我们添加一个带有 main 方法的应用程序类该方法将成为启动 Spring Boot 应用程序的入口点。该类上有SpringBootApplication注解它隐含地添加了几个方便的功能自动配置、组件扫描等 - 参见 Spring Boot 文档
package com.liuhm;import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication
Slf4j
public class CamundaApplication {public static void main(String[] args) {try {SpringApplication.run(CamundaApplication.class, args);}catch (Exception e){log.error(ExceptionUtils.getStackTrace(e));}}
}
1.4. 启动Spring Boot工程
在IDEA的maven操作窗口执行mvn clean install命令下载相关的第三方Jar包。
1.4.1. 启动
我们的第一个 Camunda Spring Boot 应用程序现已准备就绪此程序是一个 Spring Boot 应用程序它作为 Web 容器、Camunda 引擎和 Camunda Web 应用程序资源嵌入到 Tomcat 中并使用了mysql 数据库。您可以通过右键单击该类并选择CamundaApplication来运行应用程序。 1.4.2. 访问
现在在浏览器中打开 http://localhost:8080/ 时您可以使用我们之前配置的登录名和密码“admin/123456”来访问 Camunda Web 应用程序。 能正常登录访问这个界面表示基于springboot集成camunda成功了。
1.4.3. 数据库表
数据库也创建了表 执行完成后通过工具打开数据库控制台查看一共有49张表。
执行的sql脚本找到camunda-bpm-platform-7.19.0\engine\src\main\resources\org\camunda\bpm\engine\db\create文件夹下的数据库脚本选择mysql脚本依次执行即可。 2.设计并部署一个BPMN流程
我们将学习如何使用camunda流程设计器设计一个BPMN2的业务流程并部署流程。
2.1.下载安装流程设计器
官网下载Camunda Modeler官网下载(https://camunda.com/download/modeler/) 直接下载地址https://downloads.camunda.cloud/release/camunda-modeler/5.29.0/camunda-modeler-5.29.0-win-x64.zip
下载 流程设计器后camunda-modeler后只需将下载内容解压缩到您选择的文件夹中即可。
成功解压缩后对于 Windows 用户运行Camunda Modeler.exe对于 Mac 用户或 Linux 用户运行.sh文件启动流程建模器。
2.2. 设计BPMN流程
首先使用 Camunda Modeler 对可执行流程进行建模。设置两个人工任务节点配置流程处理人为admin用户。 流程模型bpmn内容:
?xml version1.0 encodingUTF-8?
bpmn:definitions xmlns:bpmnhttp://www.omg.org/spec/BPMN/20100524/MODEL xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI xmlns:dchttp://www.omg.org/spec/DD/20100524/DC xmlns:camundahttp://camunda.org/schema/1.0/bpmn xmlns:dihttp://www.omg.org/spec/DD/20100524/DI xmlns:modelerhttp://camunda.org/schema/modeler/1.0 idDefinitions_0p1akz6 targetNamespacehttp://bpmn.io/schema/bpmn exporterCamunda Modeler exporterVersion5.29.0 modeler:executionPlatformCamunda Platform modeler:executionPlatformVersion7.22.0bpmn:process idtest1 isExecutabletruebpmn:startEvent idStartEvent_1bpmn:outgoingFlow_1747ke5/bpmn:outgoing/bpmn:startEventbpmn:sequenceFlow idFlow_1747ke5 sourceRefStartEvent_1 targetRefActivity_14mnow7 /bpmn:userTask idActivity_14mnow7 name申请 camunda:assigneeadminbpmn:incomingFlow_1747ke5/bpmn:incomingbpmn:outgoingFlow_0t3binq/bpmn:outgoing/bpmn:userTaskbpmn:sequenceFlow idFlow_0t3binq sourceRefActivity_14mnow7 targetRefActivity_1ezp043 /bpmn:userTask idActivity_1ezp043 name审批 camunda:assigneeadminbpmn:incomingFlow_0t3binq/bpmn:incomingbpmn:outgoingFlow_0ug1mkb/bpmn:outgoing/bpmn:userTaskbpmn:endEvent idEvent_110i53jbpmn:incomingFlow_0ug1mkb/bpmn:incoming/bpmn:endEventbpmn:sequenceFlow idFlow_0ug1mkb sourceRefActivity_1ezp043 targetRefEvent_110i53j //bpmn:processbpmndi:BPMNDiagram idBPMNDiagram_1bpmndi:BPMNPlane idBPMNPlane_1 bpmnElementtest1bpmndi:BPMNShape idStartEvent_1_di bpmnElementStartEvent_1dc:Bounds x192 y82 width36 height36 //bpmndi:BPMNShapebpmndi:BPMNShape idActivity_106g3s5_di bpmnElementActivity_14mnow7dc:Bounds x160 y170 width100 height80 /bpmndi:BPMNLabel //bpmndi:BPMNShapebpmndi:BPMNShape idActivity_1afp88w_di bpmnElementActivity_1ezp043dc:Bounds x160 y280 width100 height80 //bpmndi:BPMNShapebpmndi:BPMNShape idEvent_110i53j_di bpmnElementEvent_110i53jdc:Bounds x192 y412 width36 height36 //bpmndi:BPMNShapebpmndi:BPMNEdge idFlow_1747ke5_di bpmnElementFlow_1747ke5di:waypoint x210 y118 /di:waypoint x210 y170 //bpmndi:BPMNEdgebpmndi:BPMNEdge idFlow_0t3binq_di bpmnElementFlow_0t3binqdi:waypoint x210 y250 /di:waypoint x210 y280 //bpmndi:BPMNEdgebpmndi:BPMNEdge idFlow_0ug1mkb_di bpmnElementFlow_0ug1mkbdi:waypoint x210 y360 /di:waypoint x210 y412 //bpmndi:BPMNEdge/bpmndi:BPMNPlane/bpmndi:BPMNDiagram
/bpmn:definitions
2.3. 发布BPMN流程
点击流程设计器左下方的发布流程按钮 3. 验证camunda流程引擎
3.1. 通过camunda web控制台测试
现在当您在浏览器中打开 http://localhost:8080/camunda/app/tasklist/ 时您可以使用我们之前配置的登录名和密码“admin/123456”来访问 Camunda Web 应用程序。 选择刚刚设计的的流程“test1”发起一个流程实例。点击左侧“Add a simple filter”添加一个默认待办任务过滤器就可以查看到刚刚提交的流程待办任务了。 此时我看打开mysql数据库表查看camunda数据库表里的数据
3.1.1. ACT_RE_DEPLOYMENT
打开流程定义发布表ACT_RE_DEPLOYMENT看到我们刚刚发布的这个流动定义模型。 3.1.2. ACT_HI_PROCINST
打开流程实例历史表ACT_HI_PROCINST看到我们刚刚发起的这个流程实例数据。 3.1.3. ACT_RU_TASK
打开流程待办任务表ACT_RU_TASK多了一条demo用户待处理的任务。 3.2. 通过camunda rest接口测试
以上我们通过camunda的web界面进行了发起流程测试验证下面我们通过Camunda REST API的方式进行测试验证。
Camunda Platform REST API官方说明文档Camunda Platform REST API 3.2.1.查询流程定义
查看流程定义rest接口http://{host}:{port}/{contextPath}/process-definition
详细接口描述见官方文档Camunda Platform REST API
用Postman测试验证http://localhost:8080/engine-rest/process-definition 返回json
[{id: test1:1:7d603a61-abc5-11ef-9172-0a0027000009,key: test1,category: http://bpmn.io/schema/bpmn,description: null,name: null,version: 1,resource: diagram_1.bpmn,deploymentId: 7d4e600f-abc5-11ef-9172-0a0027000009,diagram: null,suspended: false,tenantId: null,versionTag: null,historyTimeToLive: null,startableInTasklist: true}
]3.2.2. 发起流程实例
流程发起的rest接口为http://{host}:{port}/{contextPath}/process-definition/key/{key}/start
详细接口描述见官方文档Camunda Platform REST API
打开postman工具进行测试验证http://localhost:8080/engine-rest/process-definition/key/test1/start 输入json
{variables: {variable1: {value: hello,type: String},variable2: {value: true,type: Boolean}},businessKey: 第二次发起请求
}返回json
{links: [{method: GET,href: http://localhost:8080/engine-rest/process-instance/2f8a9efb-abc7-11ef-9172-0a0027000009,rel: self}],id: 2f8a9efb-abc7-11ef-9172-0a0027000009,definitionId: test1:1:7d603a61-abc5-11ef-9172-0a0027000009,businessKey: 第二次发起请求,caseInstanceId: null,ended: false,suspended: false,tenantId: null
}3.2.3. 查询待办任务
通过上面接口得知流程当前流转到了人工节点上那么需要查询待办任务
查询待办任务的rest接口http://{host}:{port}/{contextPath}/task
详细接口描述见官方文档Camunda Platform REST API
用Postman测试http://localhost:8080/engine-rest/task 返回json
[{id: 2f8bfe92-abc7-11ef-9172-0a0027000009,name: 申请,assignee: admin,created: 2024-11-26T15:22:26.0000800,due: null,followUp: null,lastUpdated: null,delegationState: null,description: null,executionId: 2f8a9efb-abc7-11ef-9172-0a0027000009,owner: null,parentTaskId: null,priority: 50,processDefinitionId: test1:1:7d603a61-abc5-11ef-9172-0a0027000009,processInstanceId: 2f8a9efb-abc7-11ef-9172-0a0027000009,taskDefinitionKey: Activity_14mnow7,caseExecutionId: null,caseInstanceId: null,caseDefinitionId: null,suspended: false,formKey: null,camundaFormRef: null,tenantId: null}
]3.2.4. 完成待办提交流程
完成待办任务提交流程往下走提交流程的rest服务接口为
流程发起的rest接口为http://{host}:{port}/{contextPath}/task/{id}/complete
详细接口描述见官方文档Camunda Platform REST API
用Postman测试http://localhost:8080/engine-rest/task/2f8bfe92-abc7-11ef-9172-0a0027000009/complete 输入json
{variables: {variable: {value: china},variable2: {value: false}},withVariablesInReturn: true
}返回json
{variable1: {type: String,value: hello,valueInfo: {}},variable2: {type: Boolean,value: false,valueInfo: {}},variable: {type: String,value: china,valueInfo: {}}
}3.3. 通过Java API接口测试
上面介绍了通过Camunda Web控制台界面和Camunda提供的rest接口两种方式来调用流程引擎服务。以下介绍第三种方式即Java编码方式直接调用Camunda提供的Service接口。
我们自己开发一个RestController服务类类里注入RuntimeService和TaskService的SpringBean然后调用这两个类的API接口实现发起流程和查询待办的逻辑。
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.impl.persistence.entity.TaskEntity;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;
import java.util.List;RestController
RequestMapping
public class TestController {Resourceprivate RuntimeService runtimeService;Resourceprivate TaskService taskService;/*** 通过流程定义key发起一个流程实例* param processKey 流程定义key* return 流程实例ID*/GetMapping(value /startProcessInstanceByKey/{processKey})public String startProcessInstanceByKey(PathVariable(processKey) String processKey) {ProcessInstance instance runtimeService.startProcessInstanceByKey(processKey);return instance.getRootProcessInstanceId();}/*** 查询某个用户的待办任务* param assignee 用户ID* return 待办任务列表*/GetMapping(value /getTaskByAssignee/{assignee})public String getTaskByAssignee(PathVariable(assignee) String assignee) {ListTaskEntity taskList (List)taskService.createTaskQuery().taskAssignee(assignee).list();StringBuffer sb new StringBuffer();for (Task task : taskList) {String taskTitle 待办任务IDtask.getId(),流程实例IDtask.getProcessInstanceId()\n;System.out.println(taskTitle);sb.append(taskTitle);}return sb.toString();}
}重启启动Springboot程序调用刚刚开发的流程接口进行测试。
发起一个流程实例http://localhost:8080/startProcessInstanceByKey/test1 执行成功返回了流程实例ID接着查询用户admin的待办任务
http://localhost:8080/getTaskByAssignee/admin 4. 绘制流程图介绍
4.1. 绘制
新建一个 我这边稍微画了一个具体怎么画就不在细说了最后效果如下模拟了个OA的流程 4.2. 任务分类
只介绍最常用的两种
用户任务 User Task 具体来说就是需要手动执行的任务即需要我们这变写完业务代码后调用代码
taskService.complete(taskId, variables);才会完成的任务
系统任务Service Task 系统会自动帮我们完成的任务
4.3. 网关
分为这么几类会根据我们传入的流程变量及设定的条件走 排他网关exclusive gateway
这个网关只会走一个我们走到这个网关时会从上到下找第一个符合条件的任务往下走
并行网关Parallel Gateway
这个网关不需要设置条件会走所有的任务
包含网关Inclusive Gateway
这个网关会走一个或者多个符合条件的任务
示例 如上图包含网关需要在网关的连线初设置表达式 condition
参数来自于流程变量
两个参数
switch2d 、 switch3d如果 都为true则走任务13
如果 switch2d 为true switch3d为false则只走任务1
如果 switch3d 为true switch2d为false则只走任务3
如果都为false则直接走网关然后结束
5. 任务相关API介绍
基于service的查询类都可先构建一个 query然后在附上查询条件实例几个
ListProcessDefinition list repositoryService.createProcessDefinitionQuery().list();
ListTask list taskService.createTaskQuery().taskAssignee(zhangsan).list();
ListProcessInstance instances runtimeService.createProcessInstanceQuery().listPage(1, 10);5.1. 查询历史任务
ListHistoricProcessInstance list historyService.createHistoricProcessInstanceQuery().list();5.2. 查询当前任务/分页
ListTask list taskService.createTaskQuery().orderByTaskCreateTime().desc().list();5.3. 任务回退
大体思路是拿到当前的任务及当前任务的上一个历史任务然后重启
代码示例 Task activeTask taskService.createTaskQuery().taskId(taskId).active().singleResult();
ListHistoricTaskInstance historicTaskInstance historyService.createHistoricTaskInstanceQuery().processInstanceId(instanceId).orderByHistoricActivityInstanceStartTime().desc().list();ListHistoricTaskInstance historicTaskInstances historicTaskInstance.stream().filter(v - !v.getTaskDefinitionKey().equals(activeTask.getTaskDefinitionKey())).toList();Assert.notEmpty(historicTaskInstances, 当前已是初始任务);
HistoricTaskInstance curr historicTaskInstances.get(0);runtimeService.createProcessInstanceModification(instanceId).cancelAllForActivity(activeTask.getTaskDefinitionKey()).setAnnotation(重新执行).startBeforeActivity(curr.getTaskDefinitionKey()).execute();5.4. 流程变量
包括流程中产生的变量信息包括控制流程流转的变量网关、业务表单中填写的流程需要用到的变量等。很多地方都要用到
流程变量变量传递
变量最终会存在 act_ru_variable 这个表里面
在绘制流程图的时候如果是用户任务userService 可以设置变量比如执行人 写法有这么几种方式
写死就比如 zhangsan表达式比如上面写的 ${user}这种需要传入参数其实就是启动参数的时候传入传入参数可选值为一个MapString, Object之后的流程可查看次参数上面写的是 user 所以map里面的key需要带着user不然会报错。
关于扩展变量可在流程图绘制这么设定传递方式还是一样流程图里面在下面写 代码
ProcessInstance instance runtimeService.startProcessInstanceByKey(key, new HashMap());变量设置
runtimeService.setVariable(instance.getId(), Constants.PATIENT_ID, relatedId);变量查询
Object variable runtimeService.getVariable(instance.getId(), Constants.GENERAL_ID);历史变量查询
HistoricVariableInstance variableInstance historyService.createHistoricVariableInstanceQuery().processInstanceId(bo.getId().toString()).variableName(Constants.PATIENT_ID).singleResult();
//变量值
variableInstance.getValue();
//变量名称
variableInstance.getName();5.5. 针对后端来说任务类型主要有两种。
用户任务-userTask
即需要用户参与的任务因为工作流执行过程中需要涉及到审批、过审之类的需要用户参与的任务这个时候需要用户参与然后调用接口完成任务。
服务任务-serviceTask
即自动执行的任务比如用户提交后系统自动存储、修改状态等自动完成的任务。
Type
任务类型是关键可根据配型配置实现调用 java的方法spring 的bean方法等等有这么几种类型
**Delegate Expression **推荐使用 –
在系统任务中因为是自动执行所以实际应用中需要嵌入各种业务逻辑可以在流程图设计中按照下面方式调用java代码执行在spring中配置同名的bean 配置表达式可以实现JavaDelegate接口使用类名配置快捷写法如下比较推荐下面这种此种可灵活配置bean和spring结合使用注入service等业务方法
Bean(t17)
JavaDelegate t17() {return execution - {MapString, Object variables execution.getVariables();Task task taskService.createTaskQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();//业务逻辑task.setOwner(String.valueOf(dentistId));};
}Java Class
配置java类名需要实现JavaDelegate接口注意是全路径名不可以使用Spring的bean配置
Component
public class T17Delegate implements JavaDelegate {Overridepublic void execute(DelegateExecution execution) throws Exception {String taskId execution.getId();String instanceId execution.getProcessInstanceId();MapString, Object variables execution.getVariables();}
}下面两种可使用spring的配置
Expression
EL表达式调用java类的方法 规范 expression#{monitorExecution.execution(execution)}Component(monitorExecution)
public class MonitorExecution {public void execution(DelegateExecution execution){String processInstanceId execution.getProcessInstanceId();}
}5.6.监听器
任务监听器 - Task Listener
任务监听器用于在某个与任务相关的事件发生时执行自定义Java逻辑或表达式。它只能作为用户任务的子元素添加到流程定义中。请注意这也必须作为BPMN 2.0扩展元素的子级和Camunda命名空间中发生因为任务侦听器是专门为Camunda引擎构建的。
适用场景
Bean
TaskListener t21() {return delegateTask - {String taskId delegateTask.getId();String instanceId delegateTask.getProcessInstanceId();MapString, Object variables delegateTask.getVariables();// TODO: 20log/3/22delegateTask.setVariable(, );};
}执行监听器 - Execution Listener
执行侦听器在流程执行过程中发生某些事件时执行外部Java代码或计算表达式。可以用在任何任务中可以捕获的事件有
流程实例的开始和结束。进行过渡。活动的开始和结束。网关的开始和结束。中间事件的开始和结束。结束开始事件或开始结束事件
适用场景每个任务结束时设置任务进度
public class ExampleExecutionListenerOne implements ExecutionListener {public void notify(DelegateExecution execution) throws Exception {execution.setVariable(variableSetInExecutionListener, firstValue);execution.setVariable(eventReceived, execution.getEventName());}
}5.7. 扩展属性- Extension properties
扩展属性适用于很多自定义的业务属性比如设置业务流程进度 5.8. 流程权限及创建人设置
IdentityService为鉴权相关服务但是我们实际开发中一般会用到我们自己的鉴权系统所以可以使用camunda提供的api来设置具体可以看IdentityServiceImpl这个类其中也是使用了ThreadLocal来保存鉴权信息 代码在下面
private ThreadLocalAuthentication currentAuthentication new ThreadLocalAuthentication();用户信息设置
// Userutil是我们自己封装的用户工具类
identityService.setAuthenticatedUserId(UserUtil.getUserId().toString());//获取
Authentication authentication identityService.getCurrentAuthentication();他内置很多比如开启流程时候会默认找当前登录的人这个类DefaultHistoryEventProducer
// set super process instance id
ExecutionEntity superExecution executionEntity.getSuperExecution();
if (superExecution ! null) {evt.setSuperProcessInstanceId(superExecution.getProcessInstanceId());
}//state
evt.setState(HistoricProcessInstance.STATE_ACTIVE);// set start user Id
evt.setStartUserId(Context.getCommandContext().getAuthenticatedUserId());5.9.任务执行人及发起人设置
//根据任务id设置执行人
taskService.setAssignee(task.getId(), UserUtil.getUserId().toString());博客地址
代码下载
下面的camunda-demo