activity6.0部署BPMN文件的多种方式,直接上代码
2021/4/14 10:55:17
本文主要是介绍activity6.0部署BPMN文件的多种方式,直接上代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package test; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngines; import org.activiti.engine.repository.Deployment; import org.junit.Test; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.zip.ZipInputStream; /** * @author *** * @Description: 流程BPMN部署 * @date 2021/04/04 * 在使用的时候,注意activity的数据库配置是否正确,《activiti.cfg.xml》 */ public class ProcessDefinitionTest { /**流程引擎(核心对象),默认加载类路径下命名为activiti.cfg.xml*/ ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //部署流程定义 @Test public void deployementProcessDefinition(){ Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service .createDeployment()//创建部署对象 .name("审计方案管理&审计通知书")//声明流程的名称 .addClasspathResource("process/executeSolutionApproval.bpmn")//加载资源文件,一次只能加载一个文件 .addClasspathResource("process/executeSolutionApproval.png")// .deploy();//完成部署 System.out.println("部署ID:"+deployment.getId());//1 System.out.println("部署时间:"+deployment.getDeploymentTime()); } @Test public void deployementProcessDefinitionByInputStream() throws FileNotFoundException { //获取资源相对路径 String bpmnPath = "process/executeSolutionApproval.bpmn"; String bpmnName = "executeSolutionApproval.bpmn"; String pngPath = "process/executeSolutionApproval.png"; String pngName = "executeSolutionApproval.png"; //读取资源作为一个输入流 FileInputStream bpmnfileInputStream = new FileInputStream(bpmnPath); FileInputStream pngfileInputStream = new FileInputStream(pngPath); ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service .createDeployment()//创建部署对象 .addInputStream(bpmnName,bpmnfileInputStream) .addInputStream(pngName, pngfileInputStream) .deploy();//完成部署 System.out.println("部署ID:"+deployment.getId());//1 System.out.println("部署时间:"+deployment.getDeploymentTime()); } /** * 字符串方式部署 * @throws FileNotFoundException */ @Test public void deployementProcessDefinitionByString() throws FileNotFoundException{ //字符串 String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><definitions>...</definitions>"; Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service .createDeployment()//创建部署对象 .addString("helloworld.bpmn",text) .deploy();//完成部署 System.out.println("部署ID:"+deployment.getId());//1 System.out.println("部署时间:"+deployment.getDeploymentTime()); } /** * 压缩包方式部署 * zip/bar */ @Test public void deployementProcessDefinitionByzip(){ //从classpath路径下读取资源文件 InputStream in = this.getClass().getClassLoader().getResourceAsStream("diagrams/helloworld.zip"); ZipInputStream zipInputStream = new ZipInputStream(in); Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service .createDeployment()//创建部署对象 .addZipInputStream(zipInputStream)//使用zip方式部署,将helloworld.bpmn和helloworld.png压缩成zip格式的文件 .deploy();//完成部署 System.out.println("部署ID:"+deployment.getId());//1 System.out.println("部署时间:"+deployment.getDeploymentTime()); } }
多个方式任选,另外,在部署完毕之后,!!!记得准备脚本文件避免线上翻车!!!
这篇关于activity6.0部署BPMN文件的多种方式,直接上代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-17zero-shot-learning-definition-examples-comparison
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享
- 2024-06-06基于 casdoor 的 ELK 开源登录认证解决方案: elk-auth-casdoor-icode9专业技术文章分享
- 2024-05-29Elasticsearch慢查询日志配置
- 2024-05-29揭秘华为如此多成功项目的产品关键——Charter模板
- 2024-05-29海外IDC业务拓展的7大挑战
- 2024-05-29InLine Chat功能优化对标Github Copilot,CodeGeeX带来更高效、更直观的编程体验!
- 2024-05-29CodeGeeX 智能编程助手 6 项功能升级,在Visual Studio插件市场霸榜2周!
- 2024-05-29AutoMQ 生态集成 Apache Doris
- 2024-05-292024年IDC行业的深度挖掘:机遇、挑战与未来展望