根據上篇文章springboot2.0+activiti 7 整合(一)--初識activiti和建立數據庫操做,已經把activiti的數據庫建立完成;接下來運行一個簡單的官方示例。官方demo
要運行一個activiti的demo,至少須要三部分:java
查看act_ru_task表
剛新建的數據庫是沒有任務的。
mysql
在resources目錄下,建立一個processes的文件夾,再建立bpnm文件(one-task-process.bpmn20.xml)。注意:(activiti支持的是bpmn2.0,全部bpmn文件名必定是*.bpmn20.xml結尾),由於idea的繪製工具插件默認bpmn文件是bpmn結尾。spring
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" targetNamespace="Examples"> <process id="oneTaskProcess" name="The One Task Process"> <startEvent id="theStart" /> <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" /> <userTask id="theTask" name="my task" /> <sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd" /> <endEvent id="theEnd" /> </process> </definitions>
以前建立數據庫的時候下降了mysql的版本,如今數據庫建立完成,之後的調用可使用開發過程當中mysql的版本了。我這裏就升級了mysql 的版本,使用
com.mysql.cj.jdbc.Driversql
spring: datasource: #數據源基本配置 username: root password: root url: jdbc:mysql://localhost/activiti?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&nullCatalogMeansCurrent=true&useSSL=false&useLegacyDatetimeCode=false driver-class-name: com.mysql.cj.jdbc.Driver
官方文檔是寫在main函數裏面運行,我由於平時習慣使用測試類:數據庫
package com.example.activitidemo2; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; @SpringBootTest class ActivitiDemo2ApplicationTests { @Resource RepositoryService repositoryService; @Resource RuntimeService runtimeService; @Resource TaskService taskService; @Test void contextLoads() { System.out.println("Number of process definitions : " + repositoryService.createProcessDefinitionQuery().count()); System.out.println("Number of tasks : " + taskService.createTaskQuery().count()); runtimeService.startProcessInstanceByKey("oneTaskProcess"); System.out.println("Number of tasks after process start: " + taskService.createTaskQuery().count()); } }
運行結果應以下:segmentfault
Number of process definitions : 1 Number of tasks : 0 Number of tasks after process start: 1
查看act_ru_task表
多運行幾回測試程序,任務的數量也會不斷增多。api
到此一個流程就啓動起來了,接下來開始繪製咱們本身的業務流程圖並運行。springboot