activiti no processes deployed with key ""

最近用activiti做一个很简单的小例子,自我感觉哪里都没问题,但是就是报:

org.activiti.engine.ActivitiObjectNotFoundException: no processes deployed with key 'myprocess' 

的错误,最后查资料终于找到了原因,那就是 activiti 的模版必须以  bpmn20.xml  或者 bpmn结尾;

代码如下:

目录结构:

AvtivitiAction


public class AvtivitiAction {


    @Test
    public void startProcess(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();

        DeploymentBuilder builder = repositoryService.createDeployment();
        builder.addClasspathResource("leave.bpmn20.xml");
        builder.deploy();
        // select * from `ACT_GE_PROPERTY`;这时这个表中会多条数据

        List<ProcessDefinition> p = repositoryService.createProcessDefinitionQuery().list();
        for(int i=0;i<p.size();i++){
            System.out.println(p.get(i).getKey());
        }
        RuntimeService runtimeService = processEngine.getRuntimeService();
        runtimeService.startProcessInstanceByKey("myProcess");//启动流程,ID必须与你配置的一致

        System.out.println("ok......");
    }
}


activiti.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">
   <bean id="processEngineConfiguration"
        class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
      <property name="databaseSchemaUpdate" value="false" />
      <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/qsfs" />
      <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
      <property name="jdbcUsername" value="qsfs" />
      <property name="jdbcPassword" value="qsfs" />
      <property name="jobExecutorActivate" value="true" />
   </bean>
</beans>

leave.bpmn20.xml

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             typeLanguage="http://www.w3.org/2001/XMLSchema"
             expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">


    <process id="myProcess" name="leave" >
        <startEvent id="startevent" name="start"></startEvent>
        <endEvent id="endevent" name="end"></endEvent>
        <sequenceFlow id="flowid" name="flowname" sourceRef="startevent" targetRef="endevent"></sequenceFlow>
    </process>

</definitions>


你可能感兴趣的:(activiti no processes deployed with key "")