Springboot相关--整合Flowable6.3附源码

本文档介绍了如何在SpringBoot项目中整合并使用Flowable工作流,包括引入依赖、配置数据源、流程定义的创建与部署、启动流程实例、查看与处理任务以及查看历史任务等操作。同时提到了在Tomcat中部署Flowable设计器的步骤,以及在服务器上运行时的注意事项。
摘要由CSDN通过智能技术生成

中文文档:https://tkjohn.github.io/flowable-userguide/

汉化地址:https://www.icode9.com/content-4-1237749.html

demo地址:https://gitee.com/qyh24/springboot-flowable.git

一、定义、部署流程

1.引入Flowable6.3

<!--引入Flowable6.3依赖-->
<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-spring-boot-starter</artifactId>
    <version>6.3.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

如果项目中引入了mybatisPlus,引入Flowable时一定要排除mybais,如果不排除的话,会引起以下冲突

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.getLanguageDriver(MybatisMapperAnnotationBuilder.java:385)

The following method did not exist:

    org.apache.ibatis.session.Configuration.getLanguageDriver(Ljava/lang/Class;)Lorg/apache/ibatis/scripting/LanguageDriver;

The method's class, org.apache.ibatis.session.Configuration, is available from the following locations:

    jar:file:/Users/qiaoyuhang/.m2/repository/org/mybatis/mybatis/3.4.5/mybatis-3.4.5.jar!/org/apache/ibatis/session/Configuration.class

It was loaded from the following location:

    file:/Users/qiaoyuhang/.m2/repository/org/mybatis/mybatis/3.4.5/mybatis-3.4.5.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.ibatis.session.Configuration


Process finished with exit code 1

2.配置文件

Flowable默认使用h2数据源,可以更改,我用的是mysql

# mysql
spring:
  datasource:
    url: jdbc:mysql://*:3306/flowable?useUnicode=true&characterEncoding=utf8
    username: *
    password: *
    driver-class-name: com.mysql.jdbc.Driver
@Configuration
@PropertySource("classpath:application-dev.yml")
public class FlowableConfig {

    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    @Value("${spring.datasource.driver-class-name}")
    private String driver;

    @Bean
    public ProcessEngine getProcessEngine(){
        ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl(url)
                .setJdbcUsername(username)
                .setJdbcPassword(password)
                .setJdbcDriver(driver)
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        ProcessEngine processEngine = cfg.buildProcessEngine();
        return processEngine;
    }
}

3.设计一个流程

在设计器中创建一个流程

3EA5C1D3-A210-47D7-BB95-A196AE08C6AA.png

5468EB59-E230-45AF-BA84-52CB2B7A46F9.png

4.部署流程定义

@RestController
@RequestMapping("/flowable")
@Slf4j
public class FlowableController {
    @Autowired
    private ProcessEngine processEngine;
    /**
     * 部署流程定义
     * @return
     */
    @RequestMapping("/def")
   public Deployment getDeployment(){
       RepositoryService repositoryService = processEngine.getRepositoryService();
       Deployment deployment = repositoryService.createDeployment()
               .addClasspathResource("file/请假.bpmn20.xml")
               .deploy();
       log.info("部署--{}--流程成功","请假");
       return deployment;
   }
}

部署成功后,查看ACT_RE_PROCDEF是否成功插入数据

A662F55A-ADC5-4FF4-B9B0-873998599DC8.png

5.查询流程定义

/**
 * 查询流程定义
 * @return
 */
@RequestMapping("/query")
public void getProcessDefinition(){
    RepositoryService repositoryService = processEngine.getRepositoryService();
    List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
    log.info("Found process definition : " + list.toString());
}

二、启动流程,查看任务

1.启动流程实例

/**
 * 启动流程实例
 * @return
 */
@RequestMapping("/start")
public void ProcessInstance(){
    RuntimeService runtimeService = processEngine.getRuntimeService();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("employee", "申请人");
    variables.put("nrOfHolidays", "3");
    variables.put("description", "请假3天");
    ProcessInstance processInstance =
            runtimeService.startProcessInstanceByKey("leave_key", variables);//key为xml中processId
    log.info("成功启动流程{}" ,"leave_key");
}

查看ACT_RU_EXECUTION(执行表)
ACT_RU_TASK(正在进行的任务表)
ACT_RU_VARIABLE(变量表)
ACT_HI_ACTINST(历史节点表)

2.查看任务

    /**
     * 查看任务表
     * @return
     */
    @RequestMapping("/getTask")
    public void getTaskService(){
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskAssignee("张三").list();
        System.out.println("You have " + tasks.size() + " tasks:");
        for (int i=0; i<tasks.size(); i++) {
            System.out.println((i+1) + ") " + tasks.get(i).getName());
        }
        //查看第一个任务,并且输出变量
        Map<String, Object> processVariables = taskService.getVariables(tasks.get(0).getId());
        System.out.println(processVariables.get("employee") + " wants " +
                processVariables.get("nrOfHolidays") + " of holidays. Do you approve this?");
    }
}

3.提交任务

/**
 * 完成任务
 * @return
 */
@RequestMapping("/submit")
public void submit(){
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskAssignee("张三").list();
    Map<String,Object> variables = new HashMap<String, Object>();
    variables.put("approved", true);
    taskService.complete(tasks.get(0).getId(), variables);
}

4.查看历史任务

/**
 * 根据任务分配人查看历史任务
 */
@RequestMapping("/history")
public void history(){
    HistoryService historyService = processEngine.getHistoryService();
    String name = "张三";
    List<HistoricActivityInstance> activities =
            historyService.createHistoricActivityInstanceQuery()
                    .taskAssignee(name)
                    .finished()
                    .orderByHistoricActivityInstanceEndTime().asc()
                    .list();
    activities.forEach(a->{
        Date endTime = a.getEndTime();
        String date = DateUtil.format(endTime,"yyyy-MM-dd hh:mm:ss");
        System.out.println("任务ID:" + a.getId() + "完成于:" + date);
    });
}

三、Tomcat部署Flowable设计器

1.下载Flowable

[https://github.com/flowable/flowable-engine/releases/download/flowable-6.4.0/flowable-6.4.0.zip](https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2Fflowable%2Fflowable-engine%2Freleases%2Fdownload%2Fflowable-6.4.0%2Fflowable-6.4.0.zip)

2.放入tomcat

把Flowable中5个war包放入tomcat的webapps下

C47988A2-284A-468C-951A-A6BAF35C35D0.png

3.启动完成即可登录

http://localhost:8080/flowable-modeler :

image.png

4.踩坑

网上教程大部分是本地部署,我是部署在自己的腾讯云服务器,访问地址需要进行修改

flowable-modeler/WEB-INF/classes中修改application.properties

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值