SpringBoot整合Flowable

1. 引入依赖

flowable-spring-boot-starter-basic

<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-spring-boot-starter-basic</artifactId>
    <version>${flowable.version}</version>
</dependency>

完整pom

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.16.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <java.version>1.8</java.version>
    <flowable.version>6.4.2</flowable.version>
    <slf4j.version>1.7.25</slf4j.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.4</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter-basic</artifactId>
        <version>${flowable.version}</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
</dependencies>

2. 配置文件

application.properties 主要配置数据源

server.port=10000
server.servlet.context-path=/

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/flowable-springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456

# druid config
spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=20
spring.datasource.druid.max-wait=60000
spring.datasource.druid.time-between-eviction-runs-millis=60000
spring.datasource.druid.min-evictable-idle-time-millis=300000
spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
spring.datasource.druid.filters=stat,wall,log4j
spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

3. 启动查看数据库

启动时,默认会获取 classpath*:/processes/下的所有.bpmn20.xml, .bpmn文件,并完成部署。

查看数据库,表已经自动创建。

4. 设置流程文件位置

设置流程文件位置并在启动时完成部署;

查看 org.flowable.spring.boot.FlowableProperties 完成配置

# 是否开启自动部署流程定义 默认true
flowable.check-process-definitions=true
# 流程定义文件位置
flowable.process-definition-location-prefix=classpath*:/bpmn/
# 流程文件后缀
flowable.process-definition-location-suffixes[0]=**.bpmn20.xml
flowable.process-definition-location-suffixes[1]=**.bpmn

5. 自定义ID生成器

public class CustomIdGenerator implements IdGenerator {
    @Override
    public String getNextId() {
        String uuid = UUID.randomUUID().toString();
        String nextId = "custom:" + uuid.replaceAll("-", "");
        return nextId;
    }
}
@Bean
public IdGenerator idGenerator() {
    return new CustomIdGenerator();
}

6. Flowable配置类

org.flowable.spring.boot.FlowableProperties
org.flowable.spring.boot.process.FlowableProcessProperties
org.flowable.spring.boot.app.FlowableAppProperties
org.flowable.spring.boot.idm.FlowableIdmProperties
org.flowable.spring.boot.FlowableMailProperties
org.flowable.spring.boot.FlowableHttpProperties

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot整合Flowable可以通过引入相关依赖和配置文件来实现。 首先,在配置文件中需要设置以下几个属性: - `flowable.standalone.server.enabled=false`:禁用Flowable的独立服务器模式。 - `spring.main.allow-bean-definition-overriding=true`:允许Bean的覆盖。 - `flowable.async-executor-activate=false`:关闭定时任务的执行。 - `flowable.idm.enabled=false`:禁用身份信息的检测。 - `flowable.database-schema-update=false`:禁止生成数据库表。 其次,需要在pom.xml文件中引入Flowable和Xerces的相关依赖: ``` <!-- https://mvnrepository.com/artifact/org.flowable/flowable-spring-boot-starter --> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>6.7.2</version> </dependency> <!-- https://mvnrepository.com/artifact/xerces/xercesImpl --> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.12.2</version> </dependency> ``` 最后,可以创建一个测试类,并注入所需的Flowable服务: ``` @RunWith(SpringRunner.class) @SpringBootTest(classes = BizApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class FlowableTest { @Autowired private RepositoryService repositoryService; @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; @Autowired private HistoryService historyService; } ``` 通过以上步骤,就可以在Spring Boot项目中成功整合Flowable流程引擎。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [springboot整合flowable](https://blog.csdn.net/RenshenLi/article/details/124547710)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值