springboot2+activiti7+bpmn-js使用入门

springboot2+activiti7+bpmn-js使用入门

本示例使用springboot2+activiti7+bpmn-js(vue+elementUI)环境;

官网:https://www.activiti.org/

搭建

  • 首先搭建好springboot项目的开发环境;
  • 添加maven依赖(目前git上最新版是7.1.0.M13,但是我在阿里云的maven仓库里找到的最新的是7.1.0.M6)
<properties>
    <java.version>1.8</java.version>
    <activiti.version>7.1.0.M6</activiti.version>
</properties>
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
</dependency>
<dependency>
    <groupId>org.activiti.dependencies</groupId>
    <artifactId>activiti-dependencies</artifactId>
    <version>${activiti.version}</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter</artifactId>
    <version>${activiti.version}</version>
</dependency>
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-image-generator</artifactId>
    <version>${activiti.version}</version>
</dependency>
  • 修改application.properties
# activiti配置
# 自动部署验证设置:true-开启(默认)、false-关闭
spring.activiti.check-process-definitions=false
# 自动创建表
# spring.activiti.database-schema-update=drop-create
spring.activiti.database-schema-update=false
# 使用历史表
spring.activiti.db-history-used=true
spring.activiti.history-level=full
# 关闭自动部署
spring.activiti.deployment-mode=never-fail
# 自动部署文件路径前后缀
# spring.activiti.process-definition-location-prefix=classpath:/process/
# spring.activiti.process-definition-location-suffixes=**.bpmn,**.bpmn20.xml
  • 启动类@SpringBootApplication注解加一下参数(关闭activiti自带的权限)
@SpringBootApplication(exclude = {
   
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
        org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class
})
  • 到此就可以读取指定目录下的流程配置文件使用流程了(我这里没用这种方式)。

表结构和组件

activiti工作流总共包含25张表,都已act_开头(activiti7与老版本的activiti表结构还是有些小变化的);其中:

  • ACT_GE_:通用,用在各种情况下,2张;
  • ACT_HI_:历史,8张,默认提供了4种历史级别:
    • none:不保存历史记录,性能最好;
    • activity:保存流程实例、任务、活动信息;
    • audit:默认,保存实例、任务、活动、表单属性;
    • full:保存完整的历史记录;
  • ACT_RE_:仓库,3张,保存一些静态信息,如流程定义、资源(图片,规则等);
  • ACT_RU_:运行,10张,保存流程实例、任务、变量等运行时数据,流程结束后会立即移除数据;
  • 还有两张:ACT_EVT_LOG:存储事件处理日志;ACT_PROCDEF_INFO:流程定义信息;

(老版本的activiti少了4张ACT_RU_,多了4张ACT_ID_的表(用于管理用户和用户组,作用不大))

常用的流程服务组件有:

  • RepositoryService:提供管理流程定义和部署的API;
  • RuntimeService:在流程运行时对流程实例进行管理与控制;
  • TaskService:对流程任务进行管理,如:任务提醒、任务完成和创建;
  • ManagementService:提供对流程引擎进行管理和维护的服务;
  • HistoryService:对流程历史数据进行操作;
  • DynamicBpmnService:实现在不重新部署流程的情况下对流程模型进行部分修改;

流程设计器

依赖

  • 首先需要搭建好vue+elementUI的开发环境;
  • 安装:yarn add bpmn-js bpmn-js-properties-panel(注意bpmn-js的版本不能太高,不然整合activiti可能会报错,我这里使用的这个版本)
"bpmn-js": "~7.5.0",
"bpmn-js-properties-panel": "~0.43.1",

整合activiti

bpmn-js整合activiti需要下面这个json

{
   
  "name": "Activiti",
  "uri": "http://activiti.org/bpmn",
  "prefix": "activiti",
  "xml": {
   
    "tagAlias": "lowerCase"
  },
  "associations": [],
  "types": [
    {
   
      "name": "Definitions",
      "isAbstract": true,
      "extends": [
        "bpmn:Definitions"
      ],
      "properties": [
        {
   
          "name": "diagramRelationId",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
   
      "name": "InOutBinding",
      "superClass": [
        "Element"
      ],
      "isAbstract": true,
      "properties": [
        {
   
          "name": "source",
          "isAttr": true,
          "type": "String"
        },
        {
   
          "name": "sourceExpression",
          "isAttr": true,
          "type": "String"
        },
        {
   
          "name": "target",
          "isAttr": true,
          "type": "String"
        },
        {
   
          "name": "businessKey",
          "isAttr": true,
          "type": "String"
        },
        {
   
          "name": "local",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
   
          "name": "variables",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
   
      "name": "In",
      "superClass": [
        "InOutBinding"
      ],
      "meta": {
   
        "allowedIn": [
          "bpmn:CallActivity"
        ]
      }
    },
    {
   
      "name": "Out",
      "superClass": [
        "InOutBinding"
      ],
      "meta": {
   
        "allowedIn": [
          "bpmn:CallActivity"
        ]
      }
    },
    {
   
      "name": "AsyncCapable",
      "isAbstract": true,
      "extends": [
        "bpmn:Activity",
        "bpmn:Gateway",
        "bpmn:Event"
      ],
      "properties": [
        {
   
          "name": "async",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
   
          "name": "asyncBefore",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
   
          "name": "asyncAfter",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
   
          "name": "exclusive",
          "isAttr": true,
          "type": "Boolean",
          "default": true
        }
      ]
    },
    {
   
      "name": "JobPriorized",
      "isAbstract": true,
      "extends": [
        "bpmn:Process",
        "activiti:AsyncCapable"
      ],
      "properties": [
        {
   
          "name": "jobPriority",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
   
      "name": "SignalEventDefinition",
      "isAbstract": true,
      "extends": [
        "bpmn:SignalEventDefinition"
      ],
      "properties": [
        {
   
          "name": "async",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        }
      ]
    },
    {
   
      "name": "ErrorEventDefinition",
      "isAbstract": true,
      "extends": [
        "bpmn:ErrorEventDefinition"
      ],
      "properties": [
        {
   
          "name": "errorCodeVariable",
          "isAttr": true,
          "type": "String"
        },
        {
   
          "name": "errorMessageVariable",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
   
      "name": "Error",
      "isAbstract": true,
      "extends": [
        "bpmn:Error"
      ],
      "properties": [
        {
   
          "name": "activiti:errorMessage",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
   
      "name": "PotentialStarter",
      "superClass": [
        "Element"
      ],
      "properties": [
        {
   
          "name": "resourceAssignmentExpression",
          "type": "bpmn:ResourceAssignmentExpression"
        }
      ]
    },
    {
   
      "name": "FormSupported",
      "isAbstract": true,
      "extends": [
        "bpmn:StartEvent",
        "bpmn:UserTask"
      ],
      "properties": [
        {
   
          "name"
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值