Activiti ServiceTask 接受Spring bean
Posted ESOO
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti ServiceTask 接受Spring bean相关的知识,希望对你有一定的参考价值。
当前做流程完成回调的功能,发现普通的 activiti:class 是不能自动注入spring bean的,类似如下的配置:
在网络上找到了相关解决方案,就是用activiti:expression 替换class,这样通过表达式加载的都是自定义的类,是从spring中加载的
第一个参数,execution是流程引擎的上下文,productApi是spring bean的id,web界面配置为:
监听类如下写
package com.xs.framework.activiti.tasks;
import com.xs.backProductFactory.api.product.ProductApi;
import com.xs.backProductFactory.common.enums.ProductStatusEnum;
import com.xs.backProductFactory.dto.ResponseResult;
import com.xs.backProductFactory.dto.product.ProductDto;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import java.io.Serializable;
import java.util.Date;
/**
* Created by xvshu on 2019/1/22 0022.
*/
@Service("productFactoryNewProductTask")
public class ProductFactoryNewProductTask implements Serializable
private static Logger logger = LoggerFactory.getLogger(ProductFactoryNewProductTask.class);
public void execute(DelegateExecution delegateExecution,ProductApi productApi) throws Exception
logger.info("ProductFactoryNewProductTask begin!");
Boolean val = (Boolean)delegateExecution.getVariable("pass");
// Boolean val = (Boolean) pass.getValue(delegateExecution);
logger.info("=ProductFactoryNewProductTask=>business: prossId: pass:",delegateExecution.getBusinessKey(),delegateExecution.getProcessInstanceId(),val.toString());
//修改产品状态为审核中
ProductDto pactDto = new ProductDto();
pactDto.setId(Long.valueOf(delegateExecution.getBusinessKey()));
pactDto.setStatus(ProductStatusEnum.product_status__publishing.getStatus());
ResponseResult<Integer> responseResult = productApi.update(pactDto);
logger.info("ProductFactoryNewProductTask end!");
亲测有效,有需要的直接拿走!
以上是关于Activiti ServiceTask 接受Spring bean的主要内容,如果未能解决你的问题,请参考以下文章
activiti流程引擎如果执行serviceTask时出现异常会怎么处理?
Activiti7工作流引擎:进阶篇 ServiceTask