springboot2.X整合activity6.X

本文描述了作者将公司项目中的Activiti6工作流从XML集成方式转换为SpringBoot的新方法,包括POM文件的调整、数据库配置和YAML文件的修改。文章还提到如何在SpringBoot项目中排除Security配置并提供了一个示例配置过程。
摘要由CSDN通过智能技术生成

本文背景,公司项目上有在用activiti6版本的工作流,里面集成方式是xml的形式,鄙人打算改成springboot形式集成,其中也踩了不少坑,目前整理出来的都是可以运行的正确的代码,也参考了一些其他大佬的博文,深表感谢。项目中有一套完整的登录验证流程,本文只是简单的demo但是可以替换以前的xml形式的方式,如果想要做一个独立的工作流项目那么此文不合适。此文后续的启动工作流和部署工作流都是手动完成的,项目中是自动点的公司做了框架集成的。

1. 新建springboot项目

新建springboot项目版本2.0.6.RELEASE,数据库依赖

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>study-activiti6-springboot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>study-activiti6-springboot</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 请将版本号更改为您所需的MySQL 5.7版本 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version> <!-- 请将版本号更改为您所需的MySQL 5.7版本 -->
        </dependency>
        <!-- activiti6的版本 -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter-basic</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

2. pom引入activity依赖

版本6.0.0目前最新的版本是7后续会加上7的集成,6和7的差别不是很大

        <!-- activiti6的版本 -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter-basic</artifactId>
            <version>6.0.0</version>
        </dependency>

3. 修改yml文件

让程序自动创建相关的表信息

  • database-schema-update: drop-create
  • db-history-used: true
    注意数据库连接后的那些参数都不要丢了
server:
  port: 8011
spring:
  application:
    name: study-activiti6-springboot
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/study_activiti6_springboot?nullCatalogMeansCurrent=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=convertToNull
    username: 123
    password: 123
    driver-class-name: com.mysql.jdbc.Driver
  activiti:
    #控制Activiti如何处理数据库模式 28张表。
    #false(默认):当流程引擎启动时,Activiti不会进行任何模式更新。
    #trueActiviti会在流程引擎启动时,检查数据库模式是否和引擎的表是匹配的,如果不匹配,会更新数据库模式。
    #create-drop:在流程引擎创建的时候创建模式,在流程引擎关闭的时候删除模式。 一般不用。
    #drop-create:在流程引擎开始的时候删除模式,在流程引擎结束的时候创建模式。一般不用。
    #生产环境用false
    database-schema-update: drop-create
    # 是否在启动时检查流程定义,自动部署验证设置:true-开启(默认)、false-关闭  生成表
    check-process-definitions: false
    #生成历史信息表
    db-history-used: true
    #历史记录存储等级
    history-level: full
    #检测身份信息表是否存在
    db-identity-used: true
    #加这个配置就不会一直调用了 [activiti-acquire-async-jobs]
    #业务流程简单且不涉及耗时操作,不需要激活AsyncExecutor;如果业务流程复杂且包含多个耗时环节,那么激活AsyncExecutor可能会带来显著的性能提升
    async-executor-activate: false

4. 启动项目:

修改@SpringBootApplication(exclude = SecurityAutoConfiguration.class)//排除此配置,暂时排除security的验证,真正的项目中需要打开此配置
启动完成后修改yml文件如下配置:

  • database-schema-update: false 生产环境选false避免表被清空
  • db-history-used: false 生产环境选false避免表被清空

至此一个建议版本的集成就完成了

5. 参考此博客

https://blog.csdn.net/u011767319/article/details/83622611
我的代码地址

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值