日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

activiti5第一弹-----基本的activiti示例

發布時間:2025/3/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 activiti5第一弹-----基本的activiti示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

建立一個普通的javaSE工程,工程的目錄結構如下:

需要的jar包如下:

在config文件夾下創建log4j.properties用來輸入日志,內容如下:

log4j.rootLogger=INFO, CA # ConsoleAppender log4j.appender.CA=org.apache.log4j.ConsoleAppender log4j.appender.CA.layout=org.apache.log4j.PatternLayout log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n

在config文件夾下創建activiti.cfg.xml(每個框架都有自己的配置文件,在沒有使用spring托管框架的時候,這個配置文件管理框架的全部配置),內容如下

<?xml version="1.0"?> <beans default-lazy-init="false"xsi:schemaLocation=" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://www.springframework.org/schema/beans"><beanclass="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration"id="processEngineConfiguration"> <span style="white-space:pre"> </span><!--配置數據庫信息,這里使用mysql 但是測試時推薦使用h2數據庫 見activiti自帶的demo中的配置文件<span style="font-family: Arial, Helvetica, sans-serif;">--></span> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activi" /><property name="jdbcDriver" value="com.mysql.jdbc.Driver" /><property name="jdbcUsername" value="root" /><property name="jdbcPassword" value="root" /> <span style="white-space:pre"> </span><!--當表結構不存在時,生成activiti的23個表--><property name="databaseSchemaUpdate" value="true" /> <span style="white-space:pre"> </span><!--工作流轉--><property name="jobExecutorActivate" value="true" /><!--郵件--> <span style="white-space:pre"> </span><property name="mailServerHost" value="mail.my-corp.com" /><property name="mailServerPort" value="5025" /><!--歷史--> <span style="white-space:pre"> </span><property name="history" value="full"></property></bean> </beans>

progress文件夾下建立我們的流程定義,右鍵選擇new-----other---------Activiti Diagram(之前需要安裝eclipse的activiti插件,推薦在線安裝---Name: Activiti BPMN 2.0 designer ? ??Location: http://activiti.org/designer/update/)

建立如下的流程定義

該流程右鍵選擇xml打開方式,可以得到流程的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:xsd="http://www.w3.org/2001/XMLSchema" 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/test"> <!-- 流程內的信息--> ? <process id="myProcess" name="My process" isExecutable="true"><startEvent id="startevent1" name="Start"></startEvent><userTask id="usertask1" name="User Task"></userTask><sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow><endEvent id="endevent1" name="End"></endEvent><sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow></process> <!--這些都是用來標志圖中的各種圖形的大小和位置的 --><bpmndi:BPMNDiagram id="BPMNDiagram_myProcess"><bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess"><bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"><omgdc:Bounds height="35.0" width="35.0" x="140.0" y="180.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"><omgdc:Bounds height="55.0" width="105.0" x="220.0" y="170.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"><omgdc:Bounds height="35.0" width="35.0" x="370.0" y="180.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"><omgdi:waypoint x="175.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="220.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"><omgdi:waypoint x="325.0" y="197.0"></omgdi:waypoint><omgdi:waypoint x="370.0" y="197.0"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram> </definitions>

可以得到流程的id為 myProcess,當然這是默認的,你可以隨意修改.

最后就可以編寫測試類來測試這個流程了

package activiti_001;import junit.framework.Assert;import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test;public class MyProcessTest {@Testpublic void test() {// 通過默認的資源獲得流程引擎的配置信息(默認的--當然就是activiti.cfg.xml 了)ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();// 通過配置信息獲得流程引擎ProcessEngine processEngine = configuration.buildProcessEngine();// 流程引擎是activiti的核心,也就是activiti的門戶,通過它可以獲得各種服務。// 獲得部署服務RepositoryService repositoryService = processEngine.getRepositoryService();// 獲得運行時服務RuntimeService runtimeService = processEngine.getRuntimeService();// 獲得任務服務TaskService taskService = processEngine.getTaskService();// 部署我們定義的流程repositoryService.createDeployment().addClasspathResource("MyProcess.bpmn").deploy();// 啟動定義的流程 一定要使用BYKEYProcessInstance instance = runtimeService.startProcessInstanceByKey("myProcess");// 通過任務服務來查詢任務Task task = taskService.createTaskQuery().singleResult();// 斷言任務的名稱System.out.println(task.getName());Assert.assertTrue("User Task".equals(task.getName()));// 完成任務(因為這是一個用戶任務,所以需要模擬完成一下)taskService.complete(task.getId());task = taskService.createTaskQuery().singleResult();// 流程結束}}

總結

以上是生活随笔為你收集整理的activiti5第一弹-----基本的activiti示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。