我有一个 Camunda 7.3 独立 h2-in-mem 配置,我想将其集成到我自己的应用程序中。当我基于(有效)bpmn xml 字符串创建部署时,我没有得到任何流程定义作为回报:
public String deployProcess(WorkflowDef workflowDef) throws IOException, SQLException {
//prepare resources
String name = workflowDef.getTitle()+".bpmn";
InputStream stream = new ByteArrayInputStream(workflowDef.getBpmnXml().getBytes(Charset.defaultCharset()));
//prepare deployment
RepositoryService repositoryService = processEngine.getRepositoryService();
final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
deploymentBuilder.name(workflowDef.getId());
DeploymentEntity deploymentResult;
try {
deploymentResult = (DeploymentEntity) repositoryService.createDeployment().addInputStream(name, stream).deploy();
} finally {
stream.close();
}
//read the result
String deploymentId = deploymentResult.getId();
ProcessDefinition processDef = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
//return the process definition id for later query
String processDefinitionId = processDef.getId();
return processDefinitionId;
}
注意: 对象workflowDef 只是一个包装器,其中包含来自bpmn.io 建模器的定义,例如名称和作为字符串的bpmn XML。我还确保引擎和数据库已初始化并运行。
部署后,我在该行收到 NullPointerException
String processDefinitionId = processDef.getId();
即使我尝试通过
获取定义repositoryService.createProcessDefinitionQuery().list();
我刚刚收到一个空列表。我的代码中是否存在误解?
您似乎忘记了已部署流程定义上的
isExecutable
标志。请检查您的流程模型是否包含 isExecutable
标志。如果您使用 camunda 建模器,只需在流程的属性面板中设置此选项即可。