zoukankan      html  css  js  c++  java
  • SpringBoot开发案例之整合Activiti工作流引擎

    前言

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

    搭建

    花了半天的时间对比了下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接口,存储流程实例和用户任务等动态数据

    演示

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

    说明

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

  • 相关阅读:
    自动化测试-19-测试报告分离
    自动化测试-18-测试用例目录整合
    自动化测试-17-测试框架改进-浏览器Driver分离
    自动化测试-16-测试框架改进-数据分离openpyxl读取excel数据
    自动化测试-15-测试框架改进-yml文件介绍
    自动化测试-14-测试框架改进 --ini文件读取
    自动化测试-13- 自动化测试框架开发
    自动化测试-12-PO-PageObject原理
    自动化测试-11-pycharm中windows找不到chrome解决办法
    自动化测试-10-Python 文件操作中的读写模式:open(path, '-模式-',encoding='UTF-8')
  • 原文地址:https://www.cnblogs.com/smallSevens/p/10386042.html
Copyright © 2011-2022 走看看