課件代碼:https://gitee.com/flymini/codes01/tree/master/flowable_/learn-flowable03
****
步驟如下:
<br/>
**1. 創建一個 maven 項目,`pom.xml`如下**
```xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<flowable.version>6.3.0</flowable.version>
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.12</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.9</version>
</dependency>
<!-- log start -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- log end -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.0.7.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
```
**2. `resources/log4j.properties`日志配置文件**
```properties
log4j.rootLogger=DEBUG, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n
```
**3. 進行 Flowable 配置**
```java
@Configuration
public class FlowableConfig {
/**
* 1. 配置數據源
*/
@Bean
public DataSource dataSource() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(Driver.class);
dataSource.setUrl("jdbc:mysql://localhost:3306/flowable_spring02?useUnicode=true&characterEncoding=UTF-8");
dataSource.setUsername("root");
dataSource.setPassword("root");
return dataSource;
}
/**
* 2. 配置事務管理器
*/
@Bean
public PlatformTransactionManager transactionManager() {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
transactionManager.setDataSource(this.dataSource());
return transactionManager;
}
/**
* 3. 配置SpringProcessEngineConfiguration
*/
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
//數據源
configuration.setDataSource(this.dataSource());
//事務管理器
configuration.setTransactionManager(this.transactionManager());
//表生成策略:DB_SCHEMA_UPDATE_TRUE(true)表存在則使用,不存在則創建
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//false不使用異步處理
configuration.setAsyncExecutorActivate(false);
//流程部署時自動生成對應的圖片
configuration.setCreateDiagramOnDeploy(true);
//生成流程圖參數
configuration.setProcessDiagramGenerator(new DefaultProcessDiagramGenerator());
//流程圖字體
configuration.setActivityFontName("宋體");
configuration.setAnnotationFontName("宋體");
configuration.setLabelFontName("宋體");
return configuration;
}
/**
* 4. 配置ProcessEngineFactoryBean
*/
@Bean
public ProcessEngineFactoryBean processEngineFactoryBean() {
ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
processEngineFactoryBean.setProcessEngineConfiguration(this.processEngineConfiguration());
return processEngineFactoryBean;
}
/**
* 5. 配置ProcessEngine
*/
@Bean
public ProcessEngine processEngine() {
try {
return this.processEngineFactoryBean().getObject();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 6. 獲取各種服務接口
**/
@Bean
public RuntimeService runtimeService() {
return processEngine().getRuntimeService();
}
@Bean
public IdentityService identityService() {
return processEngine().getIdentityService();
}
@Bean
public TaskService taskService() {
return processEngine().getTaskService();
}
@Bean
public HistoryService historyService() {
return processEngine().getHistoryService();
}
@Bean
public ManagementService managementService() {
return processEngine().getManagementService();
}
@Bean
public RepositoryService repositoryService() {
return processEngine().getRepositoryService();
}
@Bean
public DynamicBpmnService dynamicBpmnService() {
return processEngine().getDynamicBpmnService();
}
@Bean
public FormService formService() {
return processEngine().getFormService();
}
}
```
**4. 可以拿到各種服務接口了**
(1)如果是在測試單元中可以使用注解`@ContextConfiguration`引入配置,然后獲取接口。
```java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = FlowableConfig.class)
public class FlowableTests {
//獲取各種服務接口
@Autowired
private RepositoryService repositoryService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private HistoryService historyService;
@Autowired
private ManagementService managementService;
@Test
@Transactional //這個事務,不需要可以拿掉
public void deploymentProcess() {
//org.flowable.engine.impl.RepositoryServiceImpl@5b6e8f77
System.out.println(this.repositoryService);
}
```
(2)不是在測試單元中可以如下獲取各種接口。
```java
public class FlowableTests {
@Test
@Transactional //這個事務,不需要可以拿掉
public void deploymentProcess() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(FlowableConfig.class);
RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
//org.flowable.engine.impl.RepositoryServiceImpl@389562d6
System.out.println(repositoryService);
}
}
```
- Activiti流程引擎
- 工作流介紹
- Activiti是什么
- Activiti流程處理步驟
- Activiti環境搭建
- 搭建步驟
- 表結構介紹
- ActivitiAPI結構
- 認識流程符號
- 流程設計器的使用
- 流程處理步驟
- 亂碼問題
- 流程實例
- 流程實例是什么
- 業務標識
- 查詢流程實例
- 掛起/激活流程實例
- 個人任務
- 分配任務負責人
- 查詢待辦任務
- 辦理權限
- 流程變量
- 流程變量類型
- 流程變量作用域
- 使用流程變量控制流程
- 組任務
- 設置任務候選人
- 組任務辦理流程
- 網關
- 4種網關類型
- 排他網關
- 并行網關
- 包含網關
- 事件網關
- Spring整合Activiti
- SpringBoot整合Activiti
- Flowable流程引擎
- Flowable是什么
- Flowable與Activiti
- Flowable環境搭建
- FlowableAPI
- 流程引擎API與服務
- 流程處理步驟
- 流程部署
- 流程部署方式
- 流程定義版本
- 刪除已部署的流程
- 下載資源
- 流程實例
- 什么是流程實例
- 業務標識
- 查詢流程實例
- 掛起/激活流程實例
- 分配任務負責人
- 固定分配
- UEL表達式分配
- 監聽器分配
- 辦理權限
- 流程變量
- 流程變量類型
- 流程變量作用域
- 流程變量控制流程
- 組任務
- 設置任務候選人
- 組任務辦理流程
- 網關
- 排他網關
- 并行網關
- 包含網關
- 事件網關
- 歷史查詢
- 查詢歷史
- Spring整合Flowable
- 配置文件整合
- 配置類整合
- SpringBoot整合Flowable