1.
The process definition id attribute in the XML file is used as the process definition key property.
The process definition name attribute in the XML file is used as the process definition name property. If the name attribute is not specified, then id attribute is used as the name.
//XML文件中的流程定义ID属性用作流程定义key属性。
//XML文件中的流程定义name属性用作流程定义name属性。如果未指定name属性,则使用id属性作为名称。
2.流程图查找
If an image resource exists in the deployment that has a name of the BPMN 2.0 XML file name concatenated with the process key and an image suffix, this image is used. In our example, this would be org/activiti/expenseProcess.expense.png (or .jpg/gif). In case you have multiple images defined in one BPMN 2.0 XML file, this approach makes most sense. Each diagram image will then have the process key in its file name.
If no such image exists, am image resource in the deployment matching the name of the BPMN 2.0 XML file is searched for. In our example this would be org/activiti/expenseProcess.png
//首先寻找与流程定义的xml文件名称相同并且流程定义的ID相同且带有图片后缀(.png/.gif等)等图片
//即xml文件名.流程定义的key.png
//若无则寻找与xml文件名相同以图片后缀结尾的
2.1获取流程定义的流程图,区别与流程实例的流程图:
@RequestMapping(value = "/image")
@ResponseBody
public void getImage(HttpServletResponse response) {
InputStream inputStream=null;
OutputStream os=null;
ProcessDefinition processDefinition =repositoryService.createProcessDefinitionQuery()
.processDefinitionId("bbb1:1:db07dc52-6efc-11e9-879e-aa801846c666").singleResult();
//方式一
String diagramResourceName=processDefinition.getDiagramResourceName();
//方式二
// InputStream inputStream =repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),diagramResourceName);
inputStream=repositoryService.getProcessDiagram(processDefinition.getId());
response.setContentType("image/png");
try {
os= response.getOutputStream();
IOUtils.copy(inputStream, os);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if (os != null) {
os.flush();
os.close();
}
if (inputStream != null) {
inputStream.close();
}
}catch (IOException e) {
e.printStackTrace();
}
}
}
3.runtimeService.startProcessInstanceByKey()和runtimeService.startProcessInstanceById()区别
前者默认启动最新版的部署信息,因为无论部署多少个版本,key都是不变的。
而startProcessInstanceById方法是根据流程定义的ID进行部署的,所以可以部署以前的版本。