自建springboot2.1.X+activty7工作流demo

自建springboot2.1.X+activty7工作流demo:

环境:springboot2.1.X,maven,activty7

首先需要配置pom.xml

这里列出几个重要的依赖:

<dependency>
    <groupId>org.activiti.cloud.dependencies</groupId>
    <artifactId>activiti-cloud-dependencies</artifactId>
    <version>7.1.0.M6</version>
    <scope>import</scope>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-diagram-rest</artifactId>
    <version>5.23.0</version>
</dependency>
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter</artifactId>
    <exclusions>
        <!-- 需要排除自带的mybatis -->
        <exclusion>
            <groupId>org.mybatis</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2.下载安装IDEA 插件actiBPM

3.在目录resource下新建一个process目录作为画流程图和装流程文件.bpmn用,这样才能读取流程

 

生成png图片操作:首先将bpmn文件修改为xml文件,右键选中如图所示

 

选中红色位置,就可以生成一张图片

然后配置yml:

spring:
  #Activiti property configuration
  activiti:
    database-schema-update: true
    history-level: full
    db-history-used: true

接下里,再配置一下连接池就可以启动啦!!!

datasource:
  type: com.alibaba.druid.pool.DruidDataSource
  driver-class-name: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://localhost:3306/activity?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&nullCatalogMeansCurrent=true
  username: 
  password: 
  druid:
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    filters: stat,wall,log4j
    filter:
      stat:
        log-slow-sql: true

当console控制台中出现这样的日志,说明成功了,此时数据库中新增了一系列有关于act的表

接下来在test测试类中,就可以部署,启动工作流了,方法如下:

package com.example.feignproduct;


import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
 public class FeignproductApplicationTests {

//    @Test
//    void contextLoads() {
//    }

    /**
     * 部署
     */
    @Test
    public void deploy(){

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //部署对象
        RepositoryService repositoryService = processEngine.getRepositoryService();

//        //创建部署环境配置对象
//        DeploymentBuilder deployment = repositoryService.createDeployment();
        //部署任务
        Deployment demo = repositoryService.createDeployment().addClasspathResource("process/Demo.xml").addClasspathResource("process/Demo.png").name("demo").deploy();

        System.out.println("demo部署id:"+demo.getId()+demo.getName());
    }

    @Test
    public void queryProcessDefinition(){
        String key = "Demo";
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //部署对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
//        List<ProcessDefinition> list = processDefinitionQuery.processDefinitionKey(key).orderByProcessDefinitionVersion().desc().list();
        List<ProcessDefinition> list = processDefinitionQuery.list();

        for(ProcessDefinition pd : list){
            System.out.println("流程部署id:"+pd.getDeploymentId());
            System.out.println("流程定义名称:"+pd.getName());
            System.out.println("流程定义key:"+pd.getKey());
            System.out.println("流程定义版本:"+pd.getVersion());
        }

    }

    /**
     * 启动工作流
     */
    @Test
    public void startProcess(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("myProcess_1");
        System.out.println("流程定义ID:" + instance.getProcessDefinitionId());
        System.out.println("流程实例ID:" + instance.getId());
    }
@Test
    public void nextStep(){
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    TaskService taskService = processEngine.getTaskService();
    //将流程往下走--传表中act_ru_task中id
    taskService.complete("00623dea-4d30-11ec-817d-005056c00008");

}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

偷懒的小胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值