企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
参考文档:https://tkjohn.github.io/flowable-userguide/#springSpringBoot 课件代码:https://gitee.com/flymini/codes01/tree/master/flowable_/learn-flowable04 **** <br/> 建议:MySQL5.7+,如果MySQL低于5.7可能会报异常。 <br/> 整合步骤如下: **1. 创建一个SpringBoot项目,`pom.xml`如下** ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.12.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>6.3.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.18</version> </dependency> <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>4.4.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> ``` **2. `resources/application.yml`** ```yml spring: datasource: url: jdbc:mysql://localhost:3307/flowable_springboot?characterEncoding=utf8&useSSL=false&serverTimezone=UTC username: root password: uhg</flEt3dff type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver liquibase: enabled: false #不需要每次启动都检查数据库版本信息 flowable: database-schema-update: true #数据库更新策略,true-表存在则使用,不存在则自动创建 db-history-used: true #true-表示记录历史信息 history-level: full #记录的历史级别,full-最高级别,所有数据都记录为历史 async-executor-activate: false #关闭异步任务 check-process-definitions: false #false-不开启自动部署 #如果开启自动部署,当流程在目录`resources/processes/*.bpmn`时会自动将流程部署到数据库 ``` 更多配置参考:https://tkjohn.github.io/flowable-userguide/#springBootFlowableProperties **3. 配置引擎** ```java @Configuration public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> { /** * 防止生成的流程图片中文乱码 */ @Override public void configure(SpringProcessEngineConfiguration engineConfiguration) { engineConfiguration.setActivityFontName("宋体"); engineConfiguration.setLabelFontName("宋体"); engineConfiguration.setAnnotationFontName("宋体"); } } ``` **4. 运行启动类** 当运行启动类时,Flowable 会自动在数据库中建表。 ```java @SpringBootApplication public class FlowableBootApplication { public static void main(String[] args) { SpringApplication.run(FlowableBootApplication.class, args); } } ``` **5. 获取各种服务接口了** ```java @SpringBootTest class FlowableBootApplicationTests { @Autowired private RepositoryService repositoryService; @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; @Autowired private HistoryService historyService; @Autowired private ManagementService managementService; @Test void contextLoads() { //成功拿到服务接口org.flowable.engine.impl.RepositoryServiceImpl@1f229c40 System.out.println(repositoryService); } } ```