前言
公司最近想要使用flowable作为我们工作流引擎,主要用于各类流程审批上。在网上搜索到了很多有参考意义的文章,但有些实现细节还需要自己去摸索。本文的实战包括:
- 在项目中引入flowable的包可以使用flowable的api;
- 将flowable-ui集成到自己项目里;
- 如何使用flowable-ui创建的流程模型(我们用的是bpmn模型,所以后面的提到的流程都是指bpmn);
- 集成公司的用户认证体系;
- 自动分配
sample源码地址: https://github.com/ChangeChe/flowable
flowable集成
flowable的集成有两部分:flowable-api与flowable-ui。flowable-api主要管创建好流程后怎么使用,flowable-ui就是通过页面去编排我们的流程。
jar包引入
这里的是较新的版本6.7.0。因为自身的框架用的是springboot
,所以需要引入一个starter
。引入的包里有flowable-ui-xxx
是flowable-ui需要的包;其他是我们使用flowable-api需要的包。
<properties>
<flowable.version>6.7.0</flowable.version>
</properties>
<dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-process</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-idm-spring-configurator</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-rest</artifactId>
<version>${flowable.version}</version>
<exclusions>
<exclusion>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-modeler-conf</artifactId>
<version>${flowable.version}</version>
<exclusions>
<exclusion>
<groupId>org.flowable</groupId>
<artifactId>flowable-json-converter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-idm-conf</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-ui-idm-rest</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-engine</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-spring</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-engine-configurator</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-form-spring-configurator</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-app-engine</artifactId>
<version>${flowable.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.3.5</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
配置
# flowable配置
flowable.common.app.idm-url = /idm
flowable.modeler.app.rest-enabled = true
flowable.database-schema-update = true
flowable.process.definition-cache-limit = 1
flowable.xml.encoding = UTF-8
# mybatis配置
mybatis.mapper-locations = classpath:/META-INF/modeler-mybatis-mappings/*.xml
mybatis.config-location = classpath:/META-INF/mybatis-config.xml
mybatis.configuration-properties.blobType = BLOB
mybatis.configuration-properties.boolValue = TRUE
mybatis.configuration-properties.prefix =
Web配置
路由
@Configuration
@EnableConfigurationProperties({FlowableIdmAppProperties.class, FlowableModelerAppProperties.class})
@ComponentScan(basePackages = {
"org.flowable.ui.idm.conf",
// "org.flowable.ui.idm.security",
"org.flowable.ui.idm.service",
"org.flowable.ui.modeler.repository",
"org.flowable.ui.modeler.service",
// "org.flowable.ui.common.filter",
"org.flowable.ui.common.service",
"org.flowable.ui.common.repository",
// "org.flowable.ui.common.security",
"org.flowable.ui.common.tenant",
"org.flowable.form"
}, excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = org.flowable.ui.idm.conf.ApplicationConfiguration.class)
})
public class ApplicationConfiguration implements BeanPostProcessor {
@Bean
public ServletRegistrationBean apiServlet(ApplicationContext applicationContext) {
AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
dispatcherServletConfiguration.setParent(applicationContext);
dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
ServletRegistrationBean registrationBean = new ServletRegistrationBean(serv