整個項目的目錄結構:

pom.xml:
- <project= =
- => <modelVersion></modelVersion> <groupId></groupId> <artifactId></artifactId> <version></version> <packaging></packaging> <name></name> <url></url> <properties> <project.build.sourceEncoding></project.build.sourceEncoding> </properties> <dependencies>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>
- <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> </dependencies> </project>
activiti.cfg.xml:
- <?xml= =?> <beans=
- =
- => <bean= => <property= = /> <property= = /> <property= = /> <property= = /> <property= = /> </bean> </beans>
在 resource 下新建Activiti Diagram
可以通過這個地址安裝插件 《Activiti BPMN 2.0 designer - http://activiti.org/designer/update/ 》


將UserTask分別修改成入下圖所示

修改好ID 和 NAME然后在修改Main config中的Assignee,員工請假修改為張三,老板審批修改為老板

點擊Window--->Preferences--->Activiti--->Save Actions:將Create process definition image when saving the diagram勾選
然后保存bpmn文件的時候會自動幫你截圖
通過ProcessEngines.getDefaultProcessEngine獲取流程引擎
- //通過activiti.cfg.xml獲取流程引擎 class"java">
通過源碼可以看到 getDefaultProcessEngine方法會通過默認的activiti.cfg.xml文件名或者是activiti-context.xml文件名讀取xml文件


當獲取到的processEngine對象不為空時 就會在數據庫創建關於activiti的23張表
具體作用如下:


跟詳細的情況可以去下面這個地址了解:
http://www.cnblogs.com/llzgzljl/archive/2013/10/07/3356108.html
此時你可以在數據庫中看到act_ge_property表中插入了3條數據
將MyLeave.bpmn和MyLeave.png打包成myleave.zip文件(一定要是zip別壓縮成rar)
執行以下方法,發布請假流程:
- /**
- * 發布流程
- * 發布流程后,流程文件會保存到數據庫中
- */ @Test publicvoid
- this"myleave.zip" new
- )
- }
查看數據庫 發布的流程文件信息會保存在下面的三張表中:
我們可以通過RepositoryService獲取詳細的流程定義信息
- @Test publicvoid
-
- );
-
-
- for +pd.getId()++pd.getName()++pd.getKey()++pd.getVersion()++pd.getResourceName()++pd.getDiagramResourceName());
- }
key 和 name 就是我們原先畫bpmn時候聲明的:

使用流程定義的Key發布一個請假流程:
- /**
- * 發布流程
- */
- publicvoid * 啟動請假單流程 並獲取流程實例
- * 因為該請假單流程可以會啟動多個所以每啟動一個請假單流程都會在數據庫中插入一條新版本的流程數據
- * 通過key啟動的流程就是當前key下最新版本的流程
- *
- */ );
- +processInstance.getId()++processInstance.getActivityId());
- }
當流程發布后在 act_ru_task ,act_ru_execution, act_ru_identitylink 表中插入流程數據
接下來就可以通過用戶ID去查看該用戶的任務了
- /**
- * 查看任務
- */ @Test publicvoid
-
- )
- for +task.getId()++task.getName()++task.getAssignee()++task.getCreateTime());
- }
提出請假申請,啟動流程
查看數據庫變化 可以看到 表中的數據已經變成了老板審批相關數據
老板查看任務 ,並審批請假
- /**
- * 查看任務
- */ @Test publicvoid
-
- )
- for +task.getId()++task.getName()++task.getAssignee()++task.getCreateTime());
- }
流程完畢,可以再act_hi_actinst表中看到整個請假流程

整個流程的過程是 1.發布流程 --->2.啟動流程--->3.相關人查看任務完成並完成
數據都是存放在數據庫中