Spring Boot整合流程引擎Flowable
Spring Boot整合Flowable BPMN流程引擎,主要涉及到以下几个步骤:
- 在
pom.xml
中添加Flowable依赖。 - 配置Flowable的数据源和事务管理器。
- 创建流程引擎配置。
- 启动时自动部署流程定义。
以下是一个简化的示例代码:
pom.xml
添加Flowable依赖:
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.7.2</version>
</dependency>
application.properties
或 application.yml
配置数据源和事务管理器:
spring.datasource.url=jdbc:mysql://localhost:3306/flowable?useSSL=false
spring.datasource.username=root
spring.datasource.password=example
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
创建流程引擎配置类:
@Configuration
public class FlowableConfig {
@Bean
public ProcessEngineFactoryBean processEngine() {
ProcessEngineFactoryBean processEngine = new ProcessEngineFactoryBean();
processEngine.setProcessEngineConfiguration(processEngineConfiguration());
return processEngine;
}
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
processEngineConfiguration.setDataSource(dataSource());
processEngineConfiguration.setDatabaseSchemaUpdate("true");
processEngineConfiguration.setTransactionManager(transactionManager());
processEngineConfiguration.setAsyncExecutorEnabled(false);
processEngineConfiguration.setJobExecutorActivate(false);
return processEngineConfiguration;
}
@Bean
public DataSourceTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
// 创建数据源,可以使用Spring的数据源配置
return null;
}
}
启动时自动部署流程定义:
@Component
public class FlowableProcessDeployer implements CommandLineRunner {
private final RepositoryService repositoryService;
@Autowired
public FlowableProcessDeployer(RepositoryService repositoryService) {
评论已关闭