创建springboot项目添加相关依赖。
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
-
- <dependency>
- <groupId>org.flowablegroupId>
- <artifactId>flowable-spring-boot-starterartifactId>
- <version>7.0.1version>
- dependency>
-
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>8.0.33version>
- dependency>
-
- <dependency>
- <groupId>com.alibabagroupId>
- <artifactId>druidartifactId>
- <version>1.2.20version>
- dependency>
- <dependency>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- <scope>annotationProcessorscope>
- dependency>
-
-
- <dependency>
- <groupId>org.slf4jgroupId>
- <artifactId>slf4j-apiartifactId>
- <version>2.0.13version>
- dependency>
-
- <dependency>
- <groupId>org.slf4jgroupId>
- <artifactId>slf4j-reload4jartifactId>
- <version>2.0.13version>
- <scope>testscope>
- dependency>
-
- dependencies>
在application.yml中添加相关配置。
- spring:
- application:
- name: flowable-demo2
-
- datasource:
- driver-class-name: com.mysql.cj.jdbc.Driver
- # nullCatalogMeansCurrent=true 自动创建流程相关表
- url: jdbc:mysql://localhost:3306/flowable?useUnicode=true&allowPublicKeyRetrieval=true&characterEncoding=utf8&useSSL=false&nullCatalogMeansCurrent=true
- username: root
- password: root
- type: com.alibaba.druid.pool.DruidDataSource
-
- # flowable相关表
- flowable:
- # true 会对数据库中所有表进行更新操作。如果表不存在,则自动创建(建议开发时使用)
- database-schema-update: true
- # 关闭定时任务JOB
- async-executor-activate: false
-
- server:
- port: 8081
- logging:
- level:
- org:
- flowable: debug
选择建模器应用程序
选择要导出的建模
点击导出按钮。
将导出的文件复制到项目中。
编写测试代码。
- package org.example.flowabledemo2;
-
- import org.flowable.engine.ProcessEngine;
- import org.flowable.engine.RepositoryService;
- import org.flowable.engine.repository.Deployment;
- import org.flowable.engine.repository.DeploymentBuilder;
- import org.junit.jupiter.api.Test;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
-
- @SpringBootTest
- class FlowableDemo2ApplicationTests {
- // 提供对所有公开BPM和工作流操作的服务的访问。
- @Autowired
- private ProcessEngine processEngine;
- // 提供对流程定义和部署的存储库的访问。
- @Autowired
- private RepositoryService repositoryService;
-
- @Test
- void contextLoads() {
- // RepositoryService repositoryService1 = processEngine.getRepositoryService();
- DeploymentBuilder deployment = repositoryService.createDeployment();
- deployment.addClasspathResource("process01/FirstFlow.bpmn20.xml");
- deployment.name("第一个流程图");
- Deployment deploy = deployment.deploy();
- System.out.println("deploy.getId() = " + deploy.getId());
- }
- }
运行并打印流程ID。
在数据库中找到对应的流程定义信息。