<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
java activiti是什麼,讓我們一起了解一下?
Activiti專案是一項新的基於Apache許可的開源BPM平臺,覆蓋了業務流程管理、工作流、服務協作等領域的一個開源的、靈活的、易擴充套件的可執行流程語言框架,特色是提供了eclipse外掛,開發人員可以通過外掛直接繪畫出業務。
Activiti執行的前期支援是什麼?
1、首先我們要知道ProcessEngine物件,是Activiti工作的核心。負責生成流程執行時的各種例項及資料、監控和管理流程的執行。
2、然後是Activiti資料庫支援:
Activiti的後臺是有資料庫的支援,所有的表都以ACT_開頭。 第二部分是表示表的用途的兩個字母標識。 用途也和服務的API對應。
ACT_RE_*: 'RE'表示repository。 這個字首的表包含了流程定義和流程靜態資源 (圖片,規則,等等)。
ACT_RU_*: 'RU'表示runtime。 這些執行時的表,包含流程例項,任務,變數,非同步任務,等執行中的資料。 Activiti只在流程例項執行過程中儲存這些資料, 在流程結束時就會刪除這些記錄。 這樣執行時表可以一直很小速度很快。
ACT_ID_*: 'ID'表示identity。 這些表包含身份資訊,比如使用者,組等等。
ACT_HI_*: 'HI'表示history。 這些表包含歷史資料,比如歷史流程例項, 變數,任務等等。
ACT_GE_*: 通用資料, 用於不同場景下,如存放資原始檔。
那麼java中如何執行activiti?
說明:自定義一個簡單流程,然後在main中直接通過控制檯輸入資訊然後控制流程。
1、建立一個maven專案 引入依賴:pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> </parent> <groupId>com.jy.activiti</groupId> <artifactId>activiti6-helloworld</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!--activiti 引擎--> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>6.0.0</version> </dependency> <!-- junit 測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!-- 日誌--> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.11</version> </dependency> <!--工具類 --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>23.0</version> </dependency> <!-- 資料看看--> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.176</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
2、新增流程模板檔案:MyProcess.bpmn
<?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="second_approve" name="二級審批" isExecutable="true"> <startEvent id="startevent" name="開始"></startEvent> <userTask id="submitForm" name="填寫審批資訊"> <extensionElements> <activiti:formProperty id="message" name="申請資訊" type="string" required="true"></activiti:formProperty> <activiti:formProperty id="name" name="申請人姓名" type="string"></activiti:formProperty> <activiti:formProperty id="submitTime" name="提交時間" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty> <activiti:formProperty id="submitType" name="確認申請" type="string" required="true"></activiti:formProperty> </extensionElements> </userTask> <sequenceFlow id="flow1" sourceRef="startevent" targetRef="submitForm"></sequenceFlow> <exclusiveGateway id="decideSubmit" name="提交或取消"></exclusiveGateway> <sequenceFlow id="flow2" sourceRef="submitForm" targetRef="decideSubmit"></sequenceFlow> <userTask id="ti_approve" name="主管審批"> <extensionElements> <activiti:formProperty id="tlApprove" name="主管審批結果" type="string"></activiti:formProperty> <activiti:formProperty id="tlMessage" name="主管備註" type="string" required="true"></activiti:formProperty> </extensionElements> </userTask> <sequenceFlow id="flow3" sourceRef="decideSubmit" targetRef="ti_approve"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${submitType=="y"||submitType=="Y"}]]></conditionExpression> </sequenceFlow> <exclusiveGateway id="decideTLapprove" name="主管審批校驗"></exclusiveGateway> <sequenceFlow id="flow4" sourceRef="ti_approve" targetRef="decideTLapprove"></sequenceFlow> <userTask id="hr_approve" name="人事審批"> <extensionElements> <activiti:formProperty id="hrApprove" name="人事審批結果" type="string" required="true"></activiti:formProperty> <activiti:formProperty id="hrMessage" name="人事備註" type="string" required="true"></activiti:formProperty> </extensionElements> </userTask> <sequenceFlow id="flow5" sourceRef="decideTLapprove" targetRef="hr_approve"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${tlApprove=="y"||tlApprove=="Y"}]]></conditionExpression> </sequenceFlow> <endEvent id="endeventCancle" name="取消"></endEvent> <sequenceFlow id="flow7" sourceRef="decideSubmit" targetRef="endeventCancle"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${submitType=="n"||submitType=="N"}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow9" sourceRef="decideTLapprove" targetRef="submitForm"></sequenceFlow> <exclusiveGateway id="hrDecideApprove" name="人事審批校驗"></exclusiveGateway> <sequenceFlow id="flow10" sourceRef="hr_approve" targetRef="hrDecideApprove"></sequenceFlow> <endEvent id="endevent" name="結束"></endEvent> <sequenceFlow id="flow11" sourceRef="hrDecideApprove" targetRef="endeventCancle"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrApprove=="y"||hrApprove=="Y"}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow12" sourceRef="hrDecideApprove" targetRef="submitForm"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_second_approve"> <bpmndi:BPMNPlane bpmnElement="second_approve" id="BPMNPlane_second_approve"> <bpmndi:BPMNShape bpmnElement="startevent" id="BPMNShape_startevent"> <omgdc:Bounds height="35.0" width="35.0" x="200.0" y="230.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="submitForm" id="BPMNShape_submitForm"> <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="220.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="decideSubmit" id="BPMNShape_decideSubmit"> <omgdc:Bounds height="40.0" width="40.0" x="430.0" y="228.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="ti_approve" id="BPMNShape_ti_approve"> <omgdc:Bounds height="55.0" width="105.0" x="515.0" y="221.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="decideTLapprove" id="BPMNShape_decideTLapprove"> <omgdc:Bounds height="40.0" width="40.0" x="665.0" y="229.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="hr_approve" id="BPMNShape_hr_approve"> <omgdc:Bounds height="55.0" width="105.0" x="750.0" y="222.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endeventCancle" id="BPMNShape_endeventCancle"> <omgdc:Bounds height="35.0" width="35.0" x="540.0" y="310.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="hrDecideApprove" id="BPMNShape_hrDecideApprove"> <omgdc:Bounds height="40.0" width="40.0" x="900.0" y="230.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent" id="BPMNShape_endevent"> <omgdc:Bounds height="35.0" width="35.0" x="985.0" y="233.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="235.0" y="247.0"></omgdi:waypoint> <omgdi:waypoint x="280.0" y="247.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="385.0" y="247.0"></omgdi:waypoint> <omgdi:waypoint x="430.0" y="248.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> <omgdi:waypoint x="470.0" y="248.0"></omgdi:waypoint> <omgdi:waypoint x="515.0" y="248.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"> <omgdi:waypoint x="620.0" y="248.0"></omgdi:waypoint> <omgdi:waypoint x="665.0" y="249.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"> <omgdi:waypoint x="705.0" y="249.0"></omgdi:waypoint> <omgdi:waypoint x="750.0" y="249.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7"> <omgdi:waypoint x="450.0" y="268.0"></omgdi:waypoint> <omgdi:waypoint x="450.0" y="327.0"></omgdi:waypoint> <omgdi:waypoint x="540.0" y="327.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9"> <omgdi:waypoint x="685.0" y="269.0"></omgdi:waypoint> <omgdi:waypoint x="684.0" y="380.0"></omgdi:waypoint> <omgdi:waypoint x="522.0" y="380.0"></omgdi:waypoint> <omgdi:waypoint x="332.0" y="380.0"></omgdi:waypoint> <omgdi:waypoint x="332.0" y="275.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10"> <omgdi:waypoint x="855.0" y="249.0"></omgdi:waypoint> <omgdi:waypoint x="900.0" y="250.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11"> <omgdi:waypoint x="920.0" y="270.0"></omgdi:waypoint> <omgdi:waypoint x="557.0" y="310.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12"> <omgdi:waypoint x="920.0" y="230.0"></omgdi:waypoint> <omgdi:waypoint x="919.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="629.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="332.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="332.0" y="220.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram></definitions>