apache 工作流引擎_SpringBoot开发案例之整合Activiti工作流引擎

f730613148a68074cc19d4c1a2bbb0c5.png

前言

JBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baeyens离开JBoss后,JBPM的下一个版本jBPM5完全放弃了jBPM4的基础代码,基于Drools Flow重头来过,目前官网已经推出了JBPM7的beta版本;Tom Baeyens加入Alfresco后很快推出了新的基于jBPM4的开源工作流系统Activiti。由此可以推测JBoss内部对jBPM未来版本的架构实现产生了严重的意见分歧。

环境

软件版本SpringBoot1.5.10activiti-spring-boot-starter-basic6.0

搭建

花了半天的时间对比了下JBPM 和 Activit,以及两个工作流的不同版本,最终选择了 Activiti6 来实现,理由如下:

  • JBPM 网上集成的资料甚少,且新版本相对比较笨重。
  • Activiti 相对丰富的资料,并且高度与 SpringBoot 集成,之所以选择 Activiti6 版本,是由于目前只有版本6的集成 starter。

创建 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
   <groupId>com.itstyle.bpm</groupId>
  <artifactId>spring-boot-activiti</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>spring-boot-activiti</name>
  <url>http://maven.apache.org</url>
  <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <!-- 截止2019年2月1日 spring-boot 2.0 没有相关 activiti 的 starter-basic-->
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/>
  </parent>
  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter-basic</artifactId>
            <version>6.0.0</version>
        </dependency>
  </dependencies>
  <build>
        <finalName>spring-boot-activiti</finalName>
    </build>
</project>

配置 application.properties:

server.context-path=/
server.port=8080
server.session-timeout=60

server.tomcat.max-threads=100
server.tomcat.uri-encoding=UTF-8

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/spring-boot-activiti?characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto" property. Default to "create-drop" when using an embedded database, "none" otherwise.
spring.jpa.hibernate.ddl-auto = update
# Hibernate 4 naming strategy fully qualified name. Not supported with Hibernate 5.
spring.jpa.hibernate.naming.strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

#每次应用启动不检查Activiti数据表是否存在及版本号是否匹配,提升应用启动速度
spring.activiti.database-schema-update=false
#保存历史数据级别设置为full最高级别,便于历史数据的追溯
spring.activiti.history-level=full

声名为配置类 ActivitiConfig:

@Configuration//声名为配置类,继承Activiti抽象配置类
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {
    
    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource activitiDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(
            PlatformTransactionManager transactionManager,
            SpringAsyncExecutor springAsyncExecutor) throws IOException {

        return baseSpringProcessEngineConfiguration(
                activitiDataSource(),
                transactionManager,
                springAsyncExecutor);
    }
}

启动项目,会自动生成28张表:

  • act_ge_ 通用数据表,ge是general的缩写
  • act_hi_ 历史数据表,hi是history的缩写,对应HistoryService接口
  • act_id_ 身份数据表,id是identity的缩写,对应IdentityService接口
  • act_re_ 流程存储表,re是repository的缩写,对应RepositoryService接口,存储流程部署和流程定义等静态数据
  • act_ru_ 运行时数据表,ru是runtime的缩写,对应RuntimeService接口和TaskService接口,存储流程实例和用户任务等动态数据

演示

一个简单的请假流程演示:

645eba3928f3d347dfc20123c71c6000.png

20020ab5cba790bd2ca3caa7d51c5682.png

ef14e8e531d618f28007f988626b62e2.png

说明

其实开源社区有不少工作流的案例,但都不是自己想要的类型。由于工作需要,会逐步分享开发中所遇到的疑难问题和小细节,后面会开源一个简单的工作流完整实例,敬请关注。

fdc447f5abe5cc711b87271859b988b6.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值