activiti版本 5.16
产生原因:创建子流程时,businesskey 不传递。
解决如下:
1、创建监听类:
import org.activiti.engine.delegate.event.ActivitiEntityEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BusinessKeyInjectionActivitiEventListener implements ActivitiEventListener {
private Logger log = LoggerFactory.getLogger(getClass());
@Override
public void onEvent(ActivitiEvent event) {
switch (event.getType()) {
case TASK_CREATED:
if (event instanceof ActivitiEntityEvent) {
ActivitiEntityEvent activityEntityEvent = (ActivitiEntityEvent) event;
TaskEntity taskEntity = (TaskEntity) activityEntityEvent.getEntity();
ExecutionEntity exEntity = taskEntity.getExecution();
String key = exEntity.getBusinessKey();
log.info("获取当前任务的流程实例的businessKey:{}",key);
if(StringUtils.isEmpty(key)){
ExecutionEntity superExecEntity = exEntity.getSuperExecution();
key=superExecEntity.getBusinessKey();
if(StringUtils.isEmpty(key)){
key=superExecEntity.getProcessInstance().getBusinessKey();
}
log.info("获取当前任务 上一个流程实例的businessKey:{}",key);
log.info("设置当前流程实例的businessKey:{}",key);
exEntity.setBusinessKey(key);
//让businessKey生效 此处非常关键。
exEntity.updateProcessBusinessKey(key);
}
break;
}
default:
break;
}
}
@Override
public boolean isFailOnException() {
// TODO Auto-generated method stub
return false;
}
}
2、配置监听:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSourceTech" />
<property name="jobExecutorActivate" value="true" />
<!-- 其间的配置见官方demo -->
<property name="eventListeners">
<list>
<!-- businessKey空值处理监听 -->
<bean class="com.cdel.activiti.listener.BusinessKeyInjectionActivitiEventListener"/>
</list>
</property>
</bean>