《Activiti /Flowable 深入BPM工作流》--- API 方式進行流程部署
一. 問題
什麼是流程定義的部署?--怎麼用 API 方式進行部署?
二. 詳情
將線下定義的流程部署到 activiti數據庫中,這就是流程定義部署,通過調用 activiti的 api將流
程定義的 bpmn 和 png 兩個文件一個一個添加部署到 activiti 中,也可以將兩個文件打成 zip 包進行
部署。
通過接口方式進行部署:
/**
* 通過接口進行 流程定義的部署
*/
@Test
public void deployProcess1() {
//獲取 repositoryService
// (1)鏈接配置文件
ProcessEngineConfiguration configuration = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
// (2)創建引擎
ProcessEngine processEngine = configuration.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
//bpmn 輸入流
InputStream inputStream_bpmn = this.getClass()
.getClassLoader()
.getResourceAsStream("studentHoliday.bpmn");
// 圖片輸入流
InputStream inputStream_png = this
.getClass()
.getClassLoader()
.getResourceAsStream("studentHoliday.png");
// 流程部署對象
Deployment deployment = repositoryService.createDeployment()
.addInputStream("studentHoliday.bpmn", inputStream_bpmn)
.addInputStream("studentHoliday.png", inputStream_png)
.deploy();
System.out.println("流程部署Id" + deployment.getId());
System.out.println("流程部署名稱:" + deployment.getName());
}
部署過程出現異常如下:
org.activiti.engine.ActivitiException: couldn't check if tables are already present using metadata:
### Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
### Cause: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
確定數據連接是否成功, 如果是連接本地的數據庫, 去表啓動mysql 服務成功
mysql 服務啓動成功後, 部署成功截圖如下:
查看庫裏信息 Act_re_procdef 成功如下: