點擊關注公眾號,實用技術文章及時了解
工作流。通過計算機對業務流程自動化執行管理,主要解決的是「使在多個參與者之間按照某種預定義的規則自動進行傳遞文檔、信息或任務的過程,從而實現某個預期的業務目標,或者促使此目標的實現」。
Activiti7介紹Activiti是一個工作流引擎,Activiti可以將業務系統中複雜的業務流程抽取出來,使用專門的建模語言BPMN2.0進行定義,業務流程按照預先定義的流程進行執行,實現了系統的流程由Activiti進行管理,減少業務系統由於流程變更進行系統升級改造的工作量,從而提高系統的健壯性,同時也減少了系統開發維護成本。
在使用activiti之前,首先需要編寫activiti.cfg.xml配置文件。並且引入相關依賴。
<dependencies><!--activiti的核心包--><dependency><groupId>org.activiti</groupId><artifactId>activiti-engine</artifactId><version>6.0.0</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-spring</artifactId><version>6.0.0</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-bpmn-model</artifactId><version>6.0.0</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-bpmn-converter</artifactId><version>6.0.0</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-json-converter</artifactId><version>6.0.0</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-bpmn-layout</artifactId><version>6.0.0</version></dependency><dependency><groupId>org.activiti.cloud</groupId><artifactId>activiti-cloud-services-api</artifactId><version>7-201710-EA</version></dependency><dependency><groupId>aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.5.4</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.40</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.0.7.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.1.6.RELEASE</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.4.5</version></dependency><dependency><groupId>commons-dbcp</groupId><artifactId>commons-dbcp</artifactId><version>1.4</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.21</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.25</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.6</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.18</version><scope>provided</scope></dependency></dependencies>activiti.cfg.xmlactiviti的引擎配置文件,包括:ProcessEngineConfiguration的定義、數據源定義、事務管理器等。其實就是一個Spring配置文件。
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!--dbcp連接池--><beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><propertyname="driverClassName"value="com.mysql.jdbc.Driver"/><propertyname="url"value="jdbc:mysql://localhost:3306/activiti"/><propertyname="username"value="root"/><propertyname="password"value="root"/><propertyname="maxActive"value="3"/><propertyname="maxIdle"value="1"/></bean><!--在默認方式下,bean的id固定為processEngineConfiguration--><beanid="processEngineConfiguration"class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"><!--配置數據庫相關信息--><propertyname="dataSource"ref="dataSource"/><!--activiti數據庫表處理策略false(默認值):檢查數據庫的版本和依賴庫的版本,如果不匹配就拋出異常true:構建流程引擎時,執行檢查,如果需要就執行更新。如果表不存在,就創建。create-drop:構建流程引擎時創建數據庫報表,關閉流程引擎時就刪除這些表。drop-create:先刪除表再創建表。create:構建流程引擎時創建數據庫表,關閉流程引擎時不刪除這些表--><propertyname="databaseSchemaUpdate"value="true"/><propertyname="asyncExecutorActivate"value="false"/><propertyname="mailServerHost"value="mail.my-corp.com"/><propertyname="mailServerPort"value="5025"/></bean></beans>Activiti流程框架,在前期主要需要了解的就是數據庫表的創建、流程的部署、流程的啟動和各個階段任務的完成。
流程引擎配置類流程引擎配置類(ProcessEngineConfiguration),通過 ProcessEngineConfiguration 可以創建工作流引擎 ProceccEngine。
工作流引擎的創建工作流引擎的創建主要有兩種方式:默認創建方式和一般創建方式
默認創建方式ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();System.out.println(processEngine);一般創建方式//使用自定義方式創建ProcessEngineConfigurationprocessEngineConfiguration=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");//獲取流程引擎對象:通過ProcessEngineConfiguration創建ProcessEngine,此時會創建數據庫ProcessEngineprocessEngine=processEngineConfiguration.buildProcessEngine();當創建好工作流引擎後,對應的數據庫中會自動生成25張數據庫表。

ACT_GE_PROPERTY中會先展示下一次流程的ID(next.dbid),並且在下一次流程部署的時候,對下一次流程的ID進行賦值。

這裡以表名的前綴進行說明:

Activiti中還有許多的Service服務接口。這些Service 是工作流引擎提供用於進行工作流部署、執行、管理的服務接口,我們可以使用這些接口操作服務對應的數據表。擴展:最全的java面試題庫
Service創建方式通過ProcessEngine創建Service方式:
RuntimeserviceruntimeService=processEngine.getRuntimeService();RepositoryServicerepositoryService=processEngine.getRepositoryService();TaskServicetaskService=processEngine.getTaskService();Service總覽
Activiti 的資源管理類,提供了管理和控制流程發布包和流程定義的操作。使用工作流建模工具設計的業務流程圖需要使用此service將流程定義文件的內容部署到計算機。除了部署流程定義以外,還可以查詢引擎中的發布包和流程定義。
暫停或激活發布包,對應全部和特定流程定義。暫停意味着它們不能再執行任何操作了,激活是對應的反向操作。獲得多種資源,像是包含在發布包里的文件,或引擎自動生成的流程圖。獲得流程定義的pojo版本,可以用來通過java解析流程,而不必通過xml。
Activiti的流程運行管理類。可以從這個服務類中獲取很多關於流程執行相關的信息
Activiti的任務管理類。可以從這個類中獲取任務的信息。
Activiti的歷史管理類,可以查詢歷史信息,執行流程時,引擎會保存很多數據(根據配置),比如流程實例啟動時間,任務的參與者,完成任務的時間,每個流程實例的執行路徑,等等。這個服務主要通過查詢功能來獲得這些數據。
Activiti的引擎管理類,提供了對Activiti流程引擎的管理和維護功能,這些功能不在工作流驅動的應用程序中使用,主要用於Activiti 系統的日常維護。
流程圖符號說明
使用IDEA進行開發,建議下載一個插件。actiBPM插件,直接搜索下載。
流程符號、畫流程圖流程符號:事件Event,活動Activity,網關Gateway,流向
使用流程設計器畫出流程圖
創建bpmn文件,在流程設計器使用流程符號來表達流程,指定流程的key,指定任務負責人
生成png文件
創建的bpmn文件要放在resourse下的bpmn文件夾下。


注意: 當前任務流程的ID不能是數字開頭。

找到本地的文件,選擇notepad打開
<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?><definitionsxmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"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"xmlns:tns="http://www.activiti.org/test"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"expressionLanguage="http://www.w3.org/1999/XPath"id="m1611283406582"name=""targetNamespace="http://www.activiti.org/test"typeLanguage="http://www.w3.org/2001/XMLSchema"><processid="myEvection"isClosed="false"isExecutable="true"name="出差申請"processType="None"><startEventid="_2"name="StartEvent"/><userTaskactiviti:assignee="zhangsan"activiti:exclusive="true"id="_3"name="創建出差申請"/><userTaskactiviti:assignee="jerry"activiti:exclusive="true"id="_4"name="經理審批"/><userTaskactiviti:assignee="jack"activiti:exclusive="true"id="_5"name="總經理審批"/><userTaskactiviti:assignee="rose"activiti:exclusive="true"id="_6"name="財務審批"/><endEventid="_7"name="EndEvent"/><sequenceFlowid="_8"sourceRef="_2"targetRef="_3"/><sequenceFlowid="_9"sourceRef="_3"targetRef="_4"/><sequenceFlowid="_10"sourceRef="_4"targetRef="_5"/><sequenceFlowid="_11"sourceRef="_5"targetRef="_6"/><sequenceFlowid="_12"sourceRef="_6"targetRef="_7"/></process><bpmndi:BPMNDiagramdocumentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0"id="Diagram-_1"name="NewDiagram"><bpmndi:BPMNPlanebpmnElement="myEvection"><bpmndi:BPMNShapebpmnElement="_2"id="Shape-_2"><omgdc:Boundsheight="32.0"width="32.0"x="185.0"y="0.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="32.0"width="32.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShapebpmnElement="_3"id="Shape-_3"><omgdc:Boundsheight="55.0"width="85.0"x="160.0"y="85.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="55.0"width="85.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShapebpmnElement="_4"id="Shape-_4"><omgdc:Boundsheight="55.0"width="85.0"x="160.0"y="185.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="55.0"width="85.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShapebpmnElement="_5"id="Shape-_5"><omgdc:Boundsheight="55.0"width="85.0"x="160.0"y="285.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="55.0"width="85.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShapebpmnElement="_6"id="Shape-_6"><omgdc:Boundsheight="55.0"width="85.0"x="160.0"y="390.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="55.0"width="85.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShapebpmnElement="_7"id="Shape-_7"><omgdc:Boundsheight="32.0"width="32.0"x="185.0"y="475.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="32.0"width="32.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNEdgebpmnElement="_12"id="BPMNEdge__12"sourceElement="_6"targetElement="_7"><omgdi:waypointx="201.0"y="445.0"/><omgdi:waypointx="201.0"y="475.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="0.0"width="0.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdgebpmnElement="_8"id="BPMNEdge__8"sourceElement="_2"targetElement="_3"><omgdi:waypointx="201.0"y="32.0"/><omgdi:waypointx="201.0"y="85.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="0.0"width="0.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdgebpmnElement="_9"id="BPMNEdge__9"sourceElement="_3"targetElement="_4"><omgdi:waypointx="202.5"y="140.0"/><omgdi:waypointx="202.5"y="185.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="0.0"width="0.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdgebpmnElement="_11"id="BPMNEdge__11"sourceElement="_5"targetElement="_6"><omgdi:waypointx="202.5"y="340.0"/><omgdi:waypointx="202.5"y="390.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="0.0"width="0.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdgebpmnElement="_10"id="BPMNEdge__10"sourceElement="_4"targetElement="_5"><omgdi:waypointx="202.5"y="240.0"/><omgdi:waypointx="202.5"y="285.0"/><bpmndi:BPMNLabel><omgdc:Boundsheight="0.0"width="0.0"x="0.0"y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></definitions>流程的操作部署流程使用 Activiti 提供的 API 把流程圖的內容寫入到數據庫中
屬於資源操作類,使用 RepositoryService
單文件部署:把bpmn文件和png文件逐個處理
壓縮包部署:把bpmn文件和png文件打成壓縮包來處理
部署操作表:act_re_deployment、act_re_procdef、act_ge_bytearray
有時候我們會有多個流程,需要創建多個bpmn流程文件,這個時候想要同時部署,我們可以對bpmn文件進行打包壓縮,使用Zip包進行批量的部署
/***使用Zip包進行批量的部署*/@TestpublicvoiddeployProcessByZip(){//獲取流程引擎ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();//獲取RepositoryServiceRepositoryServicerepositoryService=processEngine.getRepositoryService();//流程部署//讀取資源包文件,構造成InputStreamInputStreaminputStream=this.getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip");//使用InputStream構造ZipInputStreamZipInputStreamzipInputStream=newZipInputStream(inputStream);//使用壓縮包的流,進行流程的部署Deploymentdeploy=repositoryService.createDeployment().addZipInputStream(zipInputStream).deploy();//輸出System.out.println("流程部署的ID:"+deploy.getId());System.out.println("流程部署的名稱:"+deploy.getName());}操作的數據庫表:
流程部署完成以後,需要啟動流程實例。使用 RuntimeService 根據流程定義的 key進行啟動。
核心代碼:
/***啟動流程*/publicvoidstarProcess(){//創建ProcessEngineProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();//獲取RunTimeServiceRuntimeServiceruntimeService=processEngine.getRuntimeService();//根據流程定義的ID啟動流程ProcessInstanceinstance=runtimeService.startProcessInstanceByKey("myEvection");//輸出內容System.out.println("流程定義ID:"+instance.getProcessDefinitionId());System.out.println("流程實例的ID:"+instance.getId());System.out.println("當前活動的ID:"+instance.getActivityId());}任務查詢使用 TaskService ,根據流程定義的 key ,任務負責人來進行查詢
核心代碼:
/***查詢個人待執行的任務*/@TestpublicvoidfindPersonalTaskList(){//獲取流程引擎ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();//獲取TaskServiceTaskServicetaskService=processEngine.getTaskService();//根據流程的key和任務的負責人去查詢任務List<Task>taskList=taskService.createTaskQuery().processDefinitionKey("myEvection")//流程的key.includeProcessVariables().taskAssignee("zhangsan")//要查詢的負責人.list();//輸出for(Tasktask:taskList){System.out.println("流程實例的ID:"+task.getProcessInstanceId());System.out.println("任務的ID:"+task.getId());System.out.println("任務的負責人:"+task.getAssignee());System.out.println("任務的名稱:"+task.getName());}}任務完成使用 TaskService ,用任務 ID 直接完成任務。
核心代碼:
/***完成個人任務*/@TestpublicvoidcompletTask(){Stringkey="testCandidiate";Stringassignee="張三1";//任務的負責人ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();TaskServicetaskService=processEngine.getTaskService();Tasktask=taskService.createTaskQuery().processDefinitionKey(key).taskAssignee(assignee).singleResult();if(task!=null){taskService.complete(task.getId());}}關於流程實例的掛起和激活全部流程實例的掛起和激活
/***全部流程實例的掛起和激活*/@TestpublicvoidsuspendAllProcessInstance(){//1.獲取流程引擎ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();//2.獲取RepositoryServiceRepositoryServicerepositoryService=processEngine.getRepositoryService();//3.查詢流程定義ProcessDefinitionprocessDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionKey("myEvection").singleResult();//4.獲取當前流程定義的實例是否都是掛起狀態booleanflag=processDefinition.isSuspended();//5.獲取流程定義的IDStringid=processDefinition.getId();//6.判斷是否掛起狀態。是:改為激活;否:改為掛起if(flag){//改為激活.參數1:流程定義的ID,參數2:是否激活,參數3:激活時間repositoryService.activateProcessDefinitionById(id,true,null);System.out.println("流程定義ID:"+id+"已激活");}else{//改為掛起.參數1:流程定義的ID;參數2:是否掛起;參數3:掛起時間repositoryService.suspendProcessDefinitionById(id,true,null);System.out.println("流程定義ID:"+id+"已掛起");}}單個流程實例的掛起和激活
/***單個流程實例的掛起和激活*/@TestpublicvoidsuspendSingleProcessInstance(){//1.獲取流程引擎ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();//2.獲取RuntimeServiceRuntimeServiceruntimeService=processEngine.getRuntimeService();//3.通過RuntimeService獲取流程實例對象ProcessInstanceinstance=runtimeService.createProcessInstanceQuery().processInstanceId("17501").singleResult();//4.得到當前流程實例的暫停狀態booleanflag=instance.isSuspended();//5.獲取流程實例的IDStringinstanceId=instance.getId();//6.判斷是否暫停。是:改為激活;否:改為暫停if(flag){runtimeService.activateProcessInstanceById(instanceId);System.out.println("流程實例ID:"+instanceId+"已激活");}else{runtimeService.suspendProcessInstanceById(instanceId);System.out.println("流程實例ID:"+instanceId+"已暫停");}}注意: 流程實例在掛起的狀態下是無法進行下一步操作的。擴展:最全的java面試題庫
流程變量我們在使用流程變量的時候。如果我們將一個對象存儲到一個流程變量中,那麼這個對象需要實現Serializable接口。
/***出差申請中的流程變量對象*/@NoArgsConstructor@AllArgsConstructor@DatapublicclassEvectionimplementsSerializable{privateLongid;//主鍵IDprivateIntegerdays;//出差天數privateStringevectionName;//出差單名字privateDatestartTime;//出差開始時間privateDateendTime;//出差結束時間privateStringaddress;//目的地privateStringreason;//出差原因}流程變量的作用域
在屬性上使用UEL表達式 ${assignee},assignee就是一個流程變量的名稱。

在連線上使用UEL表達式 ${days<=3},days就是一個流程變量名稱,返回結果為true或者false。

Activiti有很多種方式設置流程變量,這裡簡單介紹兩種:
啟動流程時設置流程變量
/***啟動流程*/@TestpublicvoidstartProcess(){ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();RuntimeServiceruntimeService=processEngine.getRuntimeService();//流程變量mapMap<String,Object>map=newHashMap<>();//設置流程變量Evectionevection=newEvection();evection.setDays(2);//把流程變量的pojo放入mapmap.put("evection",evection);map.put("assignee0","張三");map.put("assignee1","李經理");map.put("assignee2","王財務");map.put("assignee3","趙總經理");runtimeService.startProcessInstanceByKey("myProcess_1",map);}任務辦理時設置
/***完成任務*/@TestpublicvoidcompletTask(){ProcessEngineprocessEngine=ProcessEngines.getDefaultProcessEngine();TaskServicetaskService=processEngine.getTaskService();Evectionevection=newEvection();evection.setDays(2);Map<String,Object>map=newHashMap<>();map.put("evection",evection);Tasktask=taskService.createTaskQuery().processDefinitionKey("myProcess_2").taskAssignee("王財務0").singleResult();if(task!=null){StringtaskId=task.getId();//完成任務taskService.complete(taskId,map);}}網關用來控制流程的走向
排他網關——ExclusiveGateway用來在流程中實現決策,當流程執行到這個網關,所有的分支都會判斷條件是否為true,如果為true,則執行該分支。
注意: 排他網關只會選擇一個作為true的分支執行,如果有兩個分支都為true,排他網關會選擇ID值比較小的一條分支去執行。
如果從排他網關出去的流程所有的條件都不滿足,則會拋出異常。擴展:最全的java面試題庫
並行網關——ParallelGateway並行網關,允許流程分成多條分支,也可以把多分支匯聚到一起,並行網關的功能是基於進入和外出順序流的:
注意: 如果同一個並行網關有多個進入和多個外出順序流,它就同時具有分支和匯聚功能,這時,網關會先匯聚所有進入的順序流,然後再切分成多個並行分支。
與其他網關的主要區別是:並行網關不會解析條件,即使順序流中定義了條件,也會被忽略。
並行網關需要所有分支的全部運行完了,才會匯聚,繼續向下執行。
包含網關——InclusiveGateway包含網關可以看成是排他網關和並行網關的結合體,和排他網關一樣,可以在外出順序流上定義條件,包含網關會解析它們,但是主要的區別是:包含網關可以選擇多於一條順序流,這和並行網關一樣。
包含網關的功能是基於進入和外出順序流的。
配置文件:
<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.3.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!--工作流引擎配置對象--><beanid="processEngineConfiguration"class="org.activiti.spring.SpringProcessEngineConfiguration"><!--數據源--><propertyname="dataSource"ref="dataSource"/><!--使用Spring的事務管理器--><propertyname="transactionManager"ref="transactionManager"/><!--數據庫策略:false:默認值。activiti在啟動時,會對比數據庫表中保存的版本。如果沒有表或者版本不匹配,將拋出異常。true:activiti會對數據庫中所有表進行更新操作,如果表不存在,則會自動創建。create_drop:在activiti啟動時創建表,在關閉時刪除表(必須手動關閉引擎,才能刪除表)。drop-create:在activiti啟動時刪除原來的舊錶,然後再創建新表(不需要手動關閉引擎)。--><propertyname="databaseSchemaUpdate"value="true"/></bean><!--配置數據源--><beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><propertyname="driverClassName"value="com.mysql.jdbc.Driver"/><propertyname="url"value="jdbc:mysql://localhost:3306/actspring"/><propertyname="username"value="root"/><propertyname="password"value="root"/><propertyname="maxActive"value="3"/><propertyname="maxIdle"value="1"/></bean><!--流程引擎對象--><beanid="processEngine"class="org.activiti.spring.ProcessEngineFactoryBean"><propertyname="processEngineConfiguration"ref="processEngineConfiguration"/></bean><!--資源服務--><beanid="repositoryService"factory-bean="processEngine"factory-method="getRepositoryService"/><!--流程管理--><beanid="runtimeService"factory-bean="processEngine"factory-method="getRuntimeService"/><!--任務管理--><beanid="taskService"factory-bean="processEngine"factory-method="getTaskService"/><!--歷史管理--><beanid="historyService"factory-bean="processEngine"factory-method="getHistoryService"/><!--事務管理器--><beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><propertyname="dataSource"ref="dataSource"/></bean><!--通知--><tx:adviceid="txAdvice"transaction-manager="transactionManager"><tx:attributes><!--傳播行為--><tx:methodname="save*"propagation="REQUIRED"/><tx:methodname="insert*"propagation="REQUIRED"/><tx:methodname="delete*"propagation="REQUIRED"/><tx:methodname="update*"propagation="REQUIRED"/><tx:methodname="find*"propagation="SUPPORTS"read-only="true"/><tx:methodname="get*"propagation="SUPPORTS"read-only="true"/></tx:attributes></tx:advice></beans>Activiti和SpringBoot的整合開發配置文件:
spring:application:name:actspringbootdatasource:driver-class-name:com.mysql.jdbc.Driverurl:jdbc:mysql://localhost:3306/actspring?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true&serverTimezone=UTCusername:rootpassword:rootactiviti:#false:默認值。activiti在啟動時,會對比數據庫表中保存的版本。如果沒有表或者版本不匹配,將拋出異常#true:activiti會對數據庫中所有表進行更新操作,如果表不存在,則會自動創建#create_drop:在activiti啟動時創建表,在關閉時刪除表(必須手動關閉引擎,才能刪除表)#drop-create:在activiti啟動時刪除原來的舊錶,然後再創建新表(不需要手動關閉引擎)#線上一般使用false,開發中使用truedatabase-schema-update:true#自動部署驗證設置:true-開啟(默認)、false-關閉check-process-definitions:false#開啟歷史表db-history-used:true#歷史記錄存儲等級history-level:fullserver:port:8082推薦
Java面試題寶典
技術內卷群,一起來學習!!
PS:因為公眾號平台更改了推送規則,如果不想錯過內容,記得讀完點一下「在看」,加個「星標」,這樣每次新文章推送才會第一時間出現在你的訂閱列表里。點「在看」支持我們吧!