其他分享
首页 > 其他分享> > 自建springboot2.1.X+activty7工作流demo

自建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");

}

}

标签:activty7,springboot2.1,activiti,demo,org,println,import,processEngine,out
来源: https://blog.csdn.net/wangx221210/article/details/121875253