工作流引擎,现在Java世界使用的主流是Activiti 和 Flowable 这两款。Flowable 是Activiti 的fork 分支,所以用法其实差不多。
最理想的状态,引擎能够提供一个rest
flowable 所有的依赖都在maven center里,所以上maven center 里查一下 flowable 已经上传了依赖。
查询地址 https://search.maven.org/search?q=flowable-spring-boot-starter
现有的依赖列表
Group ID | Artifact ID | 说明 |
---|---|---|
org.flowable | flowable-spring-boot-starter | spring boot flowable 依赖 |
org.flowable | flowable-spring-boot-starter-rest-api | spring boot flowable 全部五个模块的 rest api 的依赖,已废弃 |
org.flowable | flowable-spring-boot-starter-process-rest | spring boot flowable 流程引擎 ProcessEngine rest api 的依赖 |
org.flowable | flowable-spring-boot-starter-rest-api | spring boot flowable 决策引擎 DmnEngine rest api 的依赖 |
org.flowable | flowable-spring-boot-starter-rest-api | spring boot flowable CMMN 决策引擎 CMMNEngine api 的依赖 |
其他的各位看官自行查看,此处仅列出我们需要用的。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.unreal</groupId>
<artifactId>flowable-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-process-rest</artifactId>
<version>${flowable.version}</version>
</dependency>
</dependencies>
</project>
@Bean
public RestResponseFactory restResponseFactory() {
return new RestResponseFactory(new ObjectMapper());
}
@Bean
public ContentTypeResolver contentTypeResolver() {
return new DefaultContentTypeResolver();
}
@Bean
SpringProcessEngineConfiguration processEngineConfiguration(SimpleDriverDataSource dataSource, DataSourceTransactionManager transactionManager, FormEngineConfiguration formEngineConfiguration, IdmEngineConfiguration idmEngineConfiguration) throws IOException {
SpringProcessEngineConfiguration cfg = new SpringProcessEngineConfiguration();
cfg.setDataSource(dataSource).setDatabaseSchemaUpdate("true").setAsyncExecutorActivate(true);
Resource[] resources = this.applicationContext.getResources("classpath:bpmn/process/*.bpmn20.xml");
String classPath = ResourceUtils.getURL("classpath:").getPath();
this.showResourceLog(resources);
cfg.setDeploymentResources(resources);
cfg.setTransactionManager(transactionManager);
FormEngineConfigurator formEngineConfigurator = new FormEngineConfigurator();
formEngineConfigurator.setFormEngineConfiguration(formEngineConfiguration);
cfg.addConfigurator(formEngineConfigurator);
IdmEngineConfigurator idmEngineConfigurator = new IdmEngineConfigurator();
idmEngineConfigurator.setIdmEngineConfiguration(idmEngineConfiguration);
cfg.addConfigurator(idmEngineConfigurator);
cfg.setActivityFontName("宋体");//windows 下使用 中文字体 ,linux 需要换成支持中文的字体
cfg.setLabelFontName("宋体");
cfg.setAnnotationFontName("宋体");
cfg.buildProcessEngine();
return cfg;
}
官方 tomcat 部署方式,是需要使用idm登录或者在rest-api 上使用Basic auth 来使用rest服务。
但是博文里这种方式,直接可以访问,不需要验证。
在不改变server.port 的参数时。默认端口是8080.
请求地址如下:
process-api 是 依赖了flowable-spring-boot-starter-process-rest ,
dmn-api 需要依赖flowable-spring-boot-starter-dmn-rest ,
cmmn-api 需要依赖flowable-spring-boot-starter-cmmn-rest
官方网站上有 rest -api 的说明,请自行查看
https://www.flowable.org/docs/userguide/index.html#restApiChapter
Postman 导入下面的测试集合自行玩一下吧
链接: https://pan.baidu.com/s/1gRPw9O-LO-NCMVL3tl0Faw
提取码: 3k9k