最近用activiti作一個很簡單的小例子,自我感受哪裏都沒問題,可是就是報:java
的錯誤,最後查資料終於找到了緣由,那就是 activiti 的模版必須以 bpmn20.xml 或者 bpmn結尾;
mysql
代碼以下:spring
目錄結構:sql
AvtivitiActionexpress
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
ui
<?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.xmlspa
<?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>