一、核心配置类

package com.magus.project.flow.config;

import com.google.common.collect.Maps;
import com.magus.project.flow.listener.ProcessStartedListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map; /**
* @Description flowable全局监听器配置类
* @author: lxk
* @Date 2020年6月17日14:44:33
*/
@Configuration
public class FlowableListenerConfig { /**
* 任务节点前置监听
* flowable监听级别参照 {@link FlowableEngineEventType} org.flowable.common.engine.api.delegate.event
*/
private static final String CUSTOMER_LISTENER_PROCESS_STARTED = "PROCESS_STARTED"; /**
* 任务节点前置监听
* 自己建立监听类实现FlowableEventListener接口
*/
private final ProcessStartedListener taskBeforeListener; @Autowired
public FlowableListenerConfig(ProcessStartedListener taskBeforeListener) {
this.taskBeforeListener = taskBeforeListener;
} /**
* 将自定义监听器纳入flowable监听
*
* @param
* @return org.flowable.spring.boot.EngineConfigurationConfigurer
*/
@Bean
public EngineConfigurationConfigurer globalListenerConfigurer() {
return engineConfiguration -> {
engineConfiguration.setTypedEventListeners(this.customFlowableListeners());
};
} /**
* 监听类配置 {@link FlowableEngineEventType} flowable监听器级别
*
* @param
* @return java.util.Map>
*/
private Map> customFlowableListeners() {
Map> listenerMap = Maps.newHashMap();
listenerMap.put(CUSTOMER_LISTENER_PROCESS_STARTED, new ArrayList<>(Collections.singletonList(taskBeforeListener)));
return listenerMap;
} }
二、监听器 package com.magus.project.flow.listener; import com.magus.framework.core.springbean.SpringContextUtils;
import com.magus.project.flow.constants.Constant;
import com.magus.project.flow.webBean.FormRelevant;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.event.impl.FlowableProcessEventImpl;
import org.springframework.stereotype.Component; /**
* 流程实例开始,监听处理类
* @author: lxk
* @create: 2020年6月17日14:47:52
**/
@Slf4j
@Component
public class ProcessStartedListener implements FlowableEventListener { @Override
public void onEvent(FlowableEvent event) {
log.error("----------前置监听器{},执行开始----------");
FlowableProcessEventImpl eventImpl = (FlowableProcessEventImpl) event;
RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);
runtimeService.setVariable(eventImpl.getExecutionId(), Constant.PROCESS_FORM_SKIP_EBABLE, true); //获取流程启动是设置的变量对象
FormRelevant formRelevant = (FormRelevant) runtimeService.getVariable(eventImpl.getExecutionId(), Constant.PROCESS_FORM_RELEVANT_KEY); log.error("----------前置监听器{},执行结束----------");
} @Override
public boolean isFailOnException() {
return false;
} @Override
public boolean isFireOnTransactionLifecycleEvent() {
return false;
} @Override
public String getOnTransaction() {
return null;
}
}

flowable流程启动时监听器的更多相关文章

  1. spring项目中监听器作用-ContextLoaderListener(项目启动时,加载一些东西到缓存中)

    作用:在启动Web容器时,自动装配Spring applicationContext.xml的配置信息. 因为它实现了ServletContextListener这个接口,在web.xml配置这个监听 ...

  2. 在web项目启动时,使用监听器来执行某个方法

    在web项目中有很多时候需要在项目启动时就执行一些方法,而且只需要执行一次,比如:加载解析自定义的配置文件.初始化数据库信息等等,在项目启动时就直接执行一些方法,可以减少很多繁琐的操作. 这里写了个简 ...

  3. SpringBoot集成Socket服务后打包(war包)启动时如何启动Socket服务(web应用外部tomcat启动)

      1.首先知道SpringBoot打包为jar和war包是不一样的(只讨论SpringBoot环境下web应用打包)     1.1.jar和war包的打开方式不一样,虽然都依赖java环境,但是j ...

  4. Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(例如顺序:1、初始化spring容器,2、初始化线程池,3、加载业务代码,将数据库中数据加载到内存中)

    最近公司要做功能迁移,原来的后台使用的Netty,现在要迁移到在uap上,也就是说所有后台的代码不能通过netty写的加载顺序加载了. 问题就来了,怎样让迁移到tomcat的代码按照原来的加载顺序进行 ...

  5. 【流程】Flowable流程定义总结

    背景 近几年,互联网企业从消费互联网向产业互联网转型.在消费互联网时期,企业面对的时C端消费者,而产业互联网面对的是B端用户. 产业互联网涉及方方面面,企业信息化的建设就是B端用户的业务之一,在企业就 ...

  6. 【Android端 APP 启动时长获取】启动时长获取方案及具体实施

    一.什么是启动时长? 1.启动时长一般包括三种场景,分别是:新装包的首次启动时长,冷启动时长.热启动时长 冷启动 和 热启动 : (1)冷启动:当启动应用时,后台没有该程序的进程,此时启动的话系统会分 ...

  7. Tomcat启动时自动加载一个类

    有时候在开发Web应用的时候,需要tomcat启动后自动加载一个用户的类,执行一些初始化方法,如从数据库中加载业务字典到内存中,因此需要在tomcat启动时就自动加载一个类,或运行一个类的方法. 可以 ...

  8. activiti 学习( 三 ) 之 流程启动者

    在启动一个流程时,我们会有将当前用户启动的流程保存起来,作为流程发起人(启动人.申请人.提交人) 而在保存这个流程启动者信息,api 没有明确规范该怎么存.所以这里我总结下我学到的保存流程启动者信息的 ...

  9. Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(优先初始化Spring IOC容器)

    JavaWebSpringTomcatCache  最近用到在Tomcat服务器启动时自动加载数据到缓存,这就需要创建一个自定义的缓存监听器并实现ServletContextListener接口,并且 ...

随机推荐

  1. LeetCode 038 Count and Say

    题目要求:Count and Say The count-and-say sequence is the sequence of integers beginning as follows:1, 11 ...

  2. IdentityServer4系列 | 常见术语说明

    一.前言 在上一篇中,我们IdentityServer4的说明,认识到是一个基于OpenID Connect协议标准的身份认证和授权程序,并简单的对基础知识的认识以及区别说明,从OAuth.OpenI ...

  3. Mybatis报错invalid comparison: java.util.Date and java.lang.String

    请求参数中两个属性确实都是date类型,数据库也确认是data类型,这个错误是因为 在这里把date类型的参数与单引号做了比较出现的,删除就可以正常运行了.

  4. PyQt(Python+Qt)学习随笔:QTableWidgetItem项数据的data和setData访问方法

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTableWidget部件中的QTableWidgetItem项数据可以通过项的data( int ...

  5. Python文件操作函数os.open、io.open、内置函数open之间的关系

    Python提供了多种文件操作方式,这里简单介绍os.open.io.open.内置函数open之间的关系: 一.内置函数open和io.open实际上是同一个函数,后者是前者的别名: 二.os.op ...

  6. PyQt(Python+Qt)学习随笔:QAbstractItemView的dragEnabled和dragDropMode属性的关系

    老猿Python博文目录 老猿Python博客地址 在<PyQt(Python+Qt)学习随笔:QAbstractItemView的dragEnabled属性的困惑>中,老猿觉得dragE ...

  7. OLLVM简单入门

    目前市面上的许多安全公司都会在保护IOS应用程序或安卓APP时都会用到OLLVM技术.譬如说顶象IOS加固.网易IOS加固等等.故而我们今天研究下OLLVM是个什么.将从(1)OLLVM是什么?OLL ...

  8. c++11-17 模板核心知识(十五)—— 解析模板之依赖型类型名称与typename Dependent Names of Types

    模板名称的问题及解决 typename规则 C++20 typename 上篇文章c++11-17 模板核心知识(十四)-- 解析模板之依赖型模板名称 Dependent Names of Templ ...

  9. go学习49天

    写文件操作 func OpenFile(name string,flag int,perm FileMode) (file *File,err error)

  10. jxl导出excel小demo

    1.首先在pom文件加入jar包 <dependency> <groupId>net.sourceforge.jexcelapi</groupId> <art ...