尝试从部署的任何进程启动实例时出错

Error while trying to start an instance from any process deployed

我在将 Camunda BPMN 与 springboot 集成时遇到问题,我创建了包含 Camunda 引擎配置的文件

@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
   SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
   log.info("--------------------SpringProcessEngineConfiguration ");

  config.setDataSource(datasource);
  PlatformTransactionManager platformTransactionManager=new JpaTransactionManager(entityManagerFactory);
  config.setTransactionManager(platformTransactionManager);

  config.setDatabaseSchemaUpdate("true");
  config.setHistory("audit");
  config.setJobExecutorActivate(true);
  config.setApplicationContext(applicationContext);
  return config;
}

@Bean
public ProcessEngineFactoryBean processEngine() {
  log.info("--------------------processEngine ");
  ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
  factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
  factoryBean.setApplicationContext(applicationContext);
  return factoryBean;
}

@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
  log.info("--------------------repositoryService ");
  return processEngine.getRepositoryService();
}

@Bean
public RuntimeService runtimeService(ProcessEngine processEngine) {
   log.info("--------------------runtimeService ");
   return processEngine.getRuntimeService();
 }

@Bean
public TaskService taskService(ProcessEngine processEngine) {
   log.info("-------------------- taskService ");
   return processEngine.getTaskService();
}

我确实成功部署了流程,我猜:我发现 2 个表只有数据,ACT_RE_DEPLOYMENTACT_GE_BYTEARRAY

但是,我在尝试从部署的任何进程启动实例时总是遇到错误。


            ProcessEngine processEngine = restProcessEngineProvider.getDefaultProcessEngine();
            log.info("processEngine {} ",processEngine.getName());
            RuntimeService runtimeService = processEngine.getRuntimeService();
            log.info("runtimeService");
            RepositoryService repositoryService = processEngine.getRepositoryService();
            log.info("repositoryService");
            InputStream stream = new ByteArrayInputStream(process.getLastXmlDefinition().getBytes(Charset.defaultCharset()));
            DeploymentEntity deploymentResult;
            try {
                deploymentResult = (DeploymentEntity) repositoryService.createDeployment()
                        .name(name)
                        .addInputStream(name, stream).deploy();             
             List<ProcessDefinition> processes=   deploymentResult.getDeployedProcessDefinitions();          
             if (processes!=null)
             {
                 log.info("process not null {} ",processes.size());
             }
             else
             {
                 log.info("process null");
             }
            } finally {
                stream.close();
            }

            //read the result
            String deploymentId = deploymentResult.getId();
            log.info("deployement id {} ",deploymentId);
            ProcessDefinition processDef = repositoryService.createProcessDefinitionQuery()
                    .processDefinitionName(name)
                    .singleResult();
            log.info("process def ...");
            //return the process definition id for later query
            String processDefinitionId="";
            if (processDef!=null)
            {
                if (processDef.getId()!=null)
                 processDefinitionId = processDef.getId();
                else
                    log.info("process def id is null");
            }
            else

            {
                log.info("process def null ");
            }

            log.info("deployed success {} ",processDefinitionId);
            runtimeService.startProcessInstanceByKey(name); 

总是得到空进程定义 org.camunda.bpm.engine.exception.NullValueException: 没有使用密钥部署的进程...

我找到了一种方法来回答我自己的问题,我想我应该 post 在这里

String fileXML=""; // set here process  xml 
ProcessEngine processEngine = restProcessEngineProvider.getDefaultProcessEngine();

RuntimeService runtimeService = processEngine.getRuntimeService();

RepositoryService repositoryService = processEngine.getRepositoryService();
InputStream stream = new ByteArrayInputStream(fileXML);
DeploymentEntity deploymentResult;

String deploiementBuild = name + "deploiement";
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(deploiementBuild);
String definitionName = name + ".bpmn";

deploymentBuilder.addInputStream(definitionName, stream);
String deploymentId = deploymentBuilder.deploy().getId();
log.info("depoiement -------------> {}", deploymentId);

List definitions = repositoryService.createProcessDefinitionQuery().list();
log.info("depoiement size ------------> {} ",definitions.size());