课件代码: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