第一种 文件方式部署
Deployment deployment = repositoryService.createDeployment()
.name("部署名称")
.addClasspathResource(filePath + fileName + ".bpmn")
.addClasspathResource("processes/images/" + fileName + ".svg")
.deploy();
filePath是相对于resources的相对路径
第二种 文件流方式部署
1.以下这种写法亲试有效
String bpmnName = "collection_management_v1.bpmn";
ClassPathResource classPathResource = new ClassPathResource("processes/collection_management_v1.bpmn");
// 读取资源作为一个输入流
InputStream bpmnfileInputStream = classPathResource.getInputStream();
Deployment deployment = repositoryService .createDeployment()
.name("部署名称")
.addInputStream(bpmnName,bpmnfileInputStream)
.deploy();//完成部署
2.以下报错提示找不到文件,解决方法暂时还没找到
//获取资源相对路径
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 = repositoryService .createDeployment()//创建部署对象
.addInputStream(bpmnName,bpmnfileInputStream)
.addInputStream(pngName, pngfileInputStream)
.deploy();//完成部署
第三种 字符串方式部署
//字符串
String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><definitions>...</definitions>";
Deployment deployment = processEngine.getRepositoryService()//获取流程定义和部署对象相关的Service
.createDeployment()//创建部署对象
.addString("helloworld.bpmn",text)
.deploy();//完成部署
第四种 压缩包方式部署
//从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();//完成部署