Activiti是领先的轻量级的,以Java为中心的开源BPMN(Business Process Modeling Notation)引擎,实现了真正的流程自动化。下面介绍如何在SpringBoot环境下使用Maven集成Activiti6,来实现流程开发。

添加依赖


  1. <dependency>
  2. <groupId>org.activiti</groupId>
  3. <artifactId>activiti-spring-boot-starter-basic</artifactId>
  4. <version>6.0.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-web</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-jdbc</artifactId>
  13. </dependency>

添加Processes目录

SpringBoot集成activiti默认会从classpath下的processes目录下读取流程定义文件,所以需要在src/main/resources目录下添加processes目录,并在目录中创建流程文件,添加目录后,目录结构变为:

如果没有processes目录,则需要修改配置spring.activiti.process-definition-location-prefix,指定流程文件存放目录。

Spring集成Activiti6默认支持**.bpmn20.xml和**.bpmn格式的流程定义文件,修改支持的文件格式,通过配置spring.activiti.process-definition-location-suffixes修改

如:


  1. spring:
  2. activiti:
  3. check-process-definitions: true #自动检查、部署流程定义文件
  4. database-schema-update: true #自动更新数据库结构
  5. process-definition-location-prefix: classpath:/processes/ #流程定义文件存放目录
  6. #process-definition-location-suffixes: #流程文件格式
  7. # - **.bpmn20.xml
  8. # - **.bpmn

启动项目时,如果没有流程部署,就不能通过自动注入,使用RuntimeService等API,依赖注入时后报错。

ActivitiProperties中定义了activiti的自动配置项,其他配置请查看ActivitiProperties属性。

添加数据源

添加数据源,项目中添加数据源,初始化数据库结构,后续保存流程数据,


  1. spring :
  2. #data source config
  3. datasource :
  4. driver : com.mysql.jdbc.Driver
  5. url: jdbc:mysql://192.168.105.10:3306/test_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true
  6. username : root
  7. password : mysql
  8. initsize : 10
  9. maxActive : 20
  10. minIdle : 10
  11. maxWait : 120000
  12. poolPreparedStatements : false
  13. maxOpenPreparedStatements : -1
  14. validationQuery : select 1
  15. testOnborrow : true
  16. testOnReturn : true
  17. testWhileIdle : true
  18. timeBetweenEvictionRunsMillis : 120000
  19. filters : log4j,stat

添加流程

在项目中添加流程,创建文件simple.bpmn,添加内容


  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="Examples" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1539757531057" name="" targetNamespace="Examples" typeLanguage="http://www.w3.org/2001/XMLSchema">
  3. <process id="oneTaskProcess" isClosed="false" name="The One Task Process" processType="None">
  4. <startEvent id="theStart"/>
  5. <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask"/>
  6. <userTask activiti:assignee="${user}" activiti:exclusive="true" id="theTask" name="my task"/>
  7. <sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd"/>
  8. <endEvent id="theEnd"/>
  9. </process>
  10. </definitions>

启动测试

编写SpringBoot启动类,启动项目,启动项目。


  1. @SpringBootApplication(scanBasePackages = "com.legao.server")
  2. @EnableSwagger2
  3. public class WorkflowServer {
  4. public static void main(String[] args) {
  5. SpringApplication.run(WorkflowServer.class, args);
  6. }
  7. }

启动时,发现启动报错,


  1. Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
  2. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

查看activiti-spring-boot-starter-basic-6.0.0.jar发现,org.activiti.spring.boot.SecurityAutoConfiguration编译报错,这时候将SecurityAutoConfiguration排除到SpringBoot启动之外,即@SpringBootApplication注解添加exclude = SecurityAutoConfiguration.class属性


  1. @SpringBootApplication(scanBasePackages = "com.legao.server", exclude = SecurityAutoConfiguration.class)
  2. @EnableSwagger2
  3. public class WorkflowServer {
  4. public static void main(String[] args) {
  5. SpringApplication.run(WorkflowServer.class, args);
  6. }
  7. }

再启动发现启动正常,这时候SpringBoot集成activiti已经启动成功,查看数据库,Activiti6运行所需的28张表也已经创建成功。


  1. ACT_EVT_LOG
  2. ACT_GE_BYTEARRAY
  3. ACT_GE_PROPERTY
  4. ACT_HI_ACTINST
  5. ACT_HI_ATTACHMENT
  6. ACT_HI_COMMENT
  7. ACT_HI_DETAIL
  8. ACT_HI_IDENTITYLINK
  9. ACT_HI_PROCINST
  10. ACT_HI_TASKINST
  11. ACT_HI_VARINST
  12. ACT_ID_GROUP
  13. ACT_ID_INFO
  14. ACT_ID_MEMBERSHIP
  15. ACT_ID_USER
  16. ACT_PROCDEF_INFO
  17. ACT_RE_DEPLOYMENT
  18. ACT_RE_MODEL
  19. ACT_RE_PROCDEF
  20. ACT_RU_DEADLETTER_JOB
  21. ACT_RU_EVENT_SUBSCR
  22. ACT_RU_EXECUTION
  23. ACT_RU_IDENTITYLINK
  24. ACT_RU_JOB
  25. ACT_RU_SUSPENDED_JOB
  26. ACT_RU_TASK
  27. ACT_RU_TIMER_JOB
  28. ACT_RU_VARIABLE

(完)

原文地址:https://blog.csdn.net/weihao_/article/details/83241662

SpringBoot2集成Activiti6的更多相关文章

  1. SpringBoot2整合activiti6环境搭建

    SpringBoot2整合activiti6环境搭建 依赖 <dependencies> <dependency> <groupId>org.springframe ...

  2. Activiti(二) springBoot2集成activiti,集成activiti在线设计器

    摘要 本篇随笔主要记录springBoot2集成activiti流程引擎,并且嵌入activiti的在线设计器,可以通过浏览器直接编辑出我们需要的流程,不需要通过eclipse或者IDEA的actiB ...

  3. springboot集成activiti6.0多数据源的配置

    最近公司开始开发springboot的项目,需要对工作流进行集成.目前activiti已经发布了7.0的版本,但是考虑到6.0版本还是比较新而且稳定的,决定还是选择activiti6.0的版本进行集成 ...

  4. springboot2集成pagehelper

    springboot2集成pagehelper超级简单,本示例直接抄袭官方示例,仅将数据库由H2改成MySQL而已. 1. pom.xml <?xml version="1.0&quo ...

  5. UidGenerator springboot2集成篇

    uid-generator 官网集成文档: https://github.com/baidu/uid-generator/blob/master/README.zh_cn.md 由于并没有提供spri ...

  6. SpringBoot2 集成三种连接池 c3p0 hikari druid

    Hikari 1.首先集成 hikari springboot默认集成,只需要简单的配置即可 1.1 首先导入包 <dependency> <groupId>com.zaxxe ...

  7. SpringBoot2 集成日志,复杂业务下的自定义实现

    本文源码:GitHub·点这里 || GitEE·点这里 一.日志体系集成 1.日志管理 在系统的开发中,最关键的一个组件工具就是日志,日志打印方便问题排查,或者生产事故回溯,日志记录用来监控并分析系 ...

  8. SSM集成activiti6.0错误集锦(一)

    项目环境 Maven构建 数据库:Orcle12c 服务器:Tomcat9 <java.version>1.8</java.version> <activiti.vers ...

  9. springboot2集成activiti出错

    报一个反射错误 java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 解决方案:http ...

随机推荐

  1. 洛谷 1083 (NOIp2012) 借教室——标记永久化线段树 / 差分+二分

    题目:https://www.luogu.org/problemnew/show/P1083 听说线段树不标记永久化会T一个点. 注意mn记录的是本层以下.带上标记的min! #include< ...

  2. 手把手教你如何玩转消息中间件(ActiveMQ) https://blog.csdn.net/cs_hnu_scw/article/details/81040834

    #情景引入小白:起床起床起床起床....快起床~我:怎么了又,大惊小怪,吓到我了.小白:我有事有事想找你,十万火急呢~~我:你能有什么事?反正我不信..那你说说看~~小白:就是我有两个小表弟,叫大白和 ...

  3. vue组件通信全面总结

    写在前面 组件间的通信是是实际开发中非常常用的一环,如何使用对项目整体设计.开发.规范都有很实际的的作用,我在项目开发中对此深有体会,总结下vue组件间通信的几种方式,讨论下各自的使用场景 文章对相关 ...

  4. LeafLet 简单使用

    Leaflet 使用 最近在Angular项目中,用到了地图,由于种种原因放弃了百度地图api使用,最后选择了leaflet,简单介绍一下. 介绍: Leaflet 是一个为移动设备设计的交互式地图的 ...

  5. 【JZOJ3887】【长郡NOIP2014模拟10.22】字符串查询

    haf 给定n个字符串和q个询问 每次询问在这n个字符串中,有多少个字符串同时满足 1. 字符串a是它的前缀 2. 字符串b是它的后缀 100%数据满足n,q≤50000,字符串长度丌超过100,任意 ...

  6. ELK之java虚拟机安装1

    建议:直接按照默认路径,下面有一个路径我有点小改动 java最新版本1.12 从官网上下载oracle官网上的jdk 1.双击这个jdk.exe 2.点击"是" 3.点击下图的&q ...

  7. SQL Server 记录(更新中...)

    sys.databases 显示所有数据库信息 sys.tables 显示当前数据库所有的表的信息 Go 向 SQL Server 实用工具发出一批 Transact-SQL 语句已结束的信号,Go本 ...

  8. python的sorted排序具体解释

    排序.在编程中常常遇到的算法.我也在几篇文章中介绍了一些关于排序的算法. 有的高级语言内置了一些排序函数.本文讲述Python在这方面的工作.供使用python的程序猿们參考,也让没有使用python ...

  9. oracle loader

    控制文件的格式    load data    infile '数据文件名'    into table 表名    (first_name position(01:14) char,     sur ...

  10. [Java]ITOO初步了解 标签: javajbosstomcat 2016-05-29 21:14 3367人阅读 评论(34)

      开始接触Java的ITOO了,这两天在搭环境,结果发现,哇,好多没接触过的东西,先写篇博客来熟悉一下这些工具. JBoss 基于Tomcat内核,青胜于蓝   Tomcat 服务器是一个免费的开放 ...