Spring Boot - activiti - 获取流程变量

SpringBoot - activiti - Get ProcessVariables

我有这段代码:

    List<ProcessInstance> instances =
                    processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).list();

instances.forEach(this::listProcessInstance);

    private void listProcessInstance (ProcessInstance processInstance) {
    
                log.info("<-------------- ProcessInstance ---------------> {} ", processInstance);
                log.info(String.valueOf(processInstance.getProcessVariables()));
                log.info("<-------------- ProcessInstance --------------->");
    
    
        }

其中 ProcessVariables 为空,但在 tabla 上有信息:

select * from ACT_RU_VARIABLE where PROC_INST_ID_ = 76759;

试试下面的代码片段,

ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceIds(processInstanceIds);
  
    List<ProcessInstance> processInstances = processInstanceQuery.list();
  
    for (ProcessInstance processInstance : processInstances) {
      log.info(processInstance.getId());
      log.info(processInstance.getProcessVariables());
    }

出于性能原因,默认查询不 return 过程变量。您必须明确告诉查询包含变量:

 List<ProcessInstance> instances = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().list();