flowable集成spring boot ----流程动态赋值

UEL表达式:
Flowable使用UEL进行表达式解析。UEL代表Unified Expression Language,是EE6规范的一部分。它是一种占位符,让我们可以在代码中动态的给它赋值。它可以用于Java服务任务(Java Service task)、执行监听器(Execution Listener)、任务监听器(Task Listener) 与 条件顺序流(Conditional sequence flow)等。
UEL表达式有两种方式:UEL-value和UEL-method.

UEL-value:解析为一个值
在这里插入图片描述在这里插入图片描述`
参数可以在流程实例开启时传入,也可以在流程流转过程中传入

 HashMap<String, Object> map = new HashMap<>();
  map.put("userId", userId);
  map.put("amount", amount);
  ProcessInstance instance =runtimeService.startProcessInstanceByKey("reimbursement", map);
Map<String, Object> variables = new HashMap<>();
variables.put("approved", passed);
taskService.complete(task.getId(), variables);

UEL-method:调用一个方法
在这里插入图片描述在使用UEL-method时,需要先将method注册到流程引擎配置的beans中,ProcessEngineConfiguration中的beans参数是一个map。当配置这个参数时,只有在这个map中声明的bean可以在表达式与脚本中使用。bean会使用你在map中指定的名字暴露。

使用
先创建一个类,定义表达式中需要用的方法

package com.example.demo.function;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FunctionService {
    private static final Logger log = LoggerFactory.getLogger(FunctionService.class);

    public String getAssignee(String value){
        return "哈哈";
    }

    public boolean isNeedExtraExamine(String amount){

        return Integer.parseInt(amount)>500;
    }


    public void taskComplate(){
        log.info("任务完成");
    }
}

将该类注册到ProcessEngineConfiguration

package com.example.demo.config;

import com.example.demo.function.FunctionService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {
    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
       
        Map map=new HashMap();
        map.put("khl_test", new FunctionService());
        engineConfiguration.setBeans(map);
    }
}

在表达式中使用
在这里插入图片描述

注意:
如果UEL表达式中的流程变量名不存在则报错。
如果UEL表达式中的流程变量值为空null,流程不按UEL表达式去执行,而是流程结束。
如果UEL表达式都不符合条件,流程结束
如果连线不设置条件,会走flow序号小的那条线,将bpmn文件后缀名改成xml就可以看到flow的序号了

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想在你的Spring Boot应用中使用Flowable BPMN流程引擎,可以通过添加`flowable-spring-boot-starter-process`依赖来实现。这个starter包含了所有的Flowable BPMN流程引擎的核心依赖。 以下是添加`flowable-spring-boot-starter-process`依赖的步骤: 1. 在你的`pom.xml`文件中添加以下依赖: ``` <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-process</artifactId> <version>${flowable.version}</version> </dependency> ``` 其中`${flowable.version}`是Flowable版本号。 2. 启用Flowable自动配置 默认情况下,Spring Boot会自动配置Flowable。如果你需要关闭自动配置,可以在`application.properties`文件中添加以下属性: ``` flowable.autoconfigure.enabled=false ``` 3. 配置数据库 Flowable需要一个数据库来存储流程定义和运行时数据。你可以在`application.properties`文件中添加以下属性来配置数据库: ``` spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/flowable?useUnicode=true&characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=root ``` 这里的例子使用MySQL数据库,你可以替换成自己的数据库。 4. 启动应用 启动应用后,Flowable会自动创建所需的数据库表和索引,并且会自动部署`classpath:/processes`目录下的所有BPMN流程定义。 以上就是在Spring Boot应用中集成Flowable BPMN流程引擎的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值