|
@ -0,0 +1,56 @@ |
|
|
|
|
|
// FlowableEngineConfig.java |
|
|
|
|
|
package com.example.demo.config.work; |
|
|
|
|
|
|
|
|
|
|
|
import org.flowable.common.engine.impl.history.HistoryLevel; |
|
|
|
|
|
import org.flowable.engine.HistoryService; |
|
|
|
|
|
import org.flowable.engine.RepositoryService; |
|
|
|
|
|
import org.flowable.engine.RuntimeService; |
|
|
|
|
|
import org.flowable.engine.TaskService; |
|
|
|
|
|
|
|
|
|
|
|
import org.flowable.spring.SpringProcessEngineConfiguration; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource; |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
public class FlowableEngineConfig { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
public SpringProcessEngineConfiguration processEngineConfiguration( |
|
|
|
|
|
@Qualifier("flowableDataSource") DataSource flowableDataSource, |
|
|
|
|
|
@Qualifier("flowableTransactionManager") PlatformTransactionManager transactionManager) { |
|
|
|
|
|
|
|
|
|
|
|
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration(); |
|
|
|
|
|
config.setDataSource(flowableDataSource); // 👈 指定 Flowable 数据源 |
|
|
|
|
|
config.setTransactionManager(transactionManager); |
|
|
|
|
|
config.setDatabaseSchemaUpdate("true"); // 自动建表 |
|
|
|
|
|
config.setHistoryLevel(HistoryLevel.FULL).setAsyncExecutorActivate(false); // 记录完整历史 |
|
|
|
|
|
// 暂时关闭异步执行器 |
|
|
|
|
|
|
|
|
|
|
|
return config; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 👇 以下 Service Bean 可选,但推荐注入,方便 Controller 使用 |
|
|
|
|
|
@Bean |
|
|
|
|
|
public RepositoryService repositoryService(SpringProcessEngineConfiguration config) { |
|
|
|
|
|
return config.buildProcessEngine().getRepositoryService(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
public RuntimeService runtimeService(SpringProcessEngineConfiguration config) { |
|
|
|
|
|
return config.buildProcessEngine().getRuntimeService(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
public TaskService taskService(SpringProcessEngineConfiguration config) { |
|
|
|
|
|
return config.buildProcessEngine().getTaskService(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
public HistoryService historyService(SpringProcessEngineConfiguration config) { |
|
|
|
|
|
return config.buildProcessEngine().getHistoryService(); |
|
|
|
|
|
} |
|
|
|
|
|
} |