监听器配置
class指定java的相对路径
delegateExpression 指定的spring的管理 name
<extensionElements>
<activiti:executionListener delegateExpression="${SgZhpgf1V1JsbFjpbPsExecuteListener}" class="com.jgpt.kpbxt.api.gongzuoliu.executeListener.zhpgf.JsbFjpbPsExecuteListener" event="start"/>
<activiti:executionListener class="com.jgpt.kpbxt.api.gongzuoliu.executeListener.zhpgf.JsbFjpbPsExecuteListener" event="end"/>
</extensionElements>
重写监听器的base类
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
/**
* 执行任务时监听器
*
* String EVENTNAME_START = "start"; 在流程实例启动时触发。
* String EVENTNAME_END = "end"; 在流程实例结束时触发。
* String EVENTNAME_TAKE = "take"; 流程连线被执行时触发。
*/
@Slf4j
public abstract class ExecuteListener implements ExecutionListener {
@Override
public final void notify(DelegateExecution execution) {
String eventName = execution.getEventName();
switch (eventName){
case EVENTNAME_START:
start(execution);
break;
case EVENTNAME_END:
end(execution);
break;
case EVENTNAME_TAKE:
take(execution);
break;
default:
break;
}
}
/**
* 开始之前 上个jiedian结束时调用
* @param execution
*/
public void start(DelegateExecution execution){
log.info("============executionListener start============");
String eventName = execution.getEventName();
String currentActivitiId = execution.getCurrentActivityId();
log.info("事件名称:" + eventName);
log.info("ActivitiId:" + currentActivitiId);
log.info("============executionListener end============");
}
/**
* 当前ren结束时调用
* @param execution
*/
public void end(DelegateExecution execution){
log.info("============executionListener end============");
String eventName = execution.getEventName();
String currentActivitiId = execution.getCurrentActivityId();
log.info("事件名称:" + eventName);
log.info("ActivitiId:" + currentActivitiId);
log.info("============executionListener end============");
}
/**
* 任务节点指针跳转时调用
* @param execution
*/
public void take(DelegateExecution execution){
log.info("============executionListener take============");
String eventName = execution.getEventName();
String currentActivitiId = execution.getCurrentActivityId();
log.info("事件名称:" + eventName);
log.info("ActivitiId:" + currentActivitiId);
log.info("============executionListener take============");
}
}
重写后具体监听类的使用如下
import com.jgpt.kpbxt.api.gongzuoliu.executeListener.ExecuteListener;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class StartExecuteListener extends ExecuteListener {
@Override
public void start(DelegateExecution execution) {
log.info("ZhpgfStartExecuteListener 。。。 ZhpgfStartExecuteListener... ");
}
@Override
public void end(DelegateExecution execution) {
super.end(execution);
}
@Override
public void take(DelegateExecution execution) {
super.take(execution);
}
}