温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

activiti 5.16 businessKey如何为null处理。

发布时间:2021-10-20 10:40:39 来源:亿速云 阅读:177 作者:柒染 栏目:大数据

本篇文章为大家展示了activiti 5.16 businessKey如何为null处理。,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

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>

上述内容就是activiti 5.16 businessKey如何为null处理。,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI