最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring boot activiti工作流的搭建與簡(jiǎn)單使用

 更新時(shí)間:2018年08月09日 10:58:46   作者:kkkder  
這篇文章主要給大家介紹了關(guān)于spring boot activiti工作流的搭建與簡(jiǎn)單使用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前言

最近一直研究springboot,根據(jù)工作需求,工作流需要作為一個(gè)單獨(dú)的微服務(wù)工程來(lái)提供給其他服務(wù)調(diào)用,現(xiàn)在簡(jiǎn)單的寫(xiě)下工作流(使用的activiti)微服務(wù)的搭建與簡(jiǎn)單使用

jdk:1.8

數(shù)據(jù)庫(kù):mysql  5.7

IDE:eclipse

springboot:1.5.8

activiti:6.0.0

1.新建空白的maven微服務(wù)架構(gòu)

新建maven項(xiàng)目的流程不在闡述,這里添加上activiti、myslq連接的依賴,只貼主要代碼

pox.xml

<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>
 <groupId>com.xxx</groupId>
 <artifactId>xxx</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <java.version>1.8</java.version>
 </properties>
 
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.8.RELEASE</version>
 </parent>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.activiti</groupId>
   <artifactId>activiti-spring-boot-starter-basic</artifactId>
   <version>6.0.0</version>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
 
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <scope>runtime</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
</project>

確認(rèn)服務(wù)是可用

2.連接服務(wù)名、服務(wù)端口、數(shù)據(jù)庫(kù)配置

在resources目錄下的application.properties(項(xiàng)目定位原因沒(méi)有使用yaml,可根據(jù)自己項(xiàng)目使用)

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/activity?characterEncoding=utf8&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
server.port=8081
server.context-path=/activity
server.session.timeout=10
server.tomcat.uri-encoding=UTF-8

確認(rèn)配置的數(shù)據(jù)庫(kù)可用

3.main

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
/**
 * Created by Guo on 2017/11/15.
 */
@SpringBootApplication
public class ActivityApp
{
 public static void main(String[] args)
 {
  SpringApplication.run(ActivityApp.class, args);
 }
}

4.service及實(shí)現(xiàn)

service:

import org.activiti.engine.task.TaskQuery;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping("/activityService")
public interface ActivityConsumerService {
 /**
 * 流程demo
 * @return
 */
 @RequestMapping(value="/startActivityDemo",method=RequestMethod.GET)
 public boolean startActivityDemo();
 
}

impl

import java.util.HashMap;
import java.util.Map;
 
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.hongguaninfo.activity.service.ActivityConsumerService;
@Service("activityService")
public class ActivityConsumerServiceImpl implements ActivityConsumerService {
 
 @Autowired
 private RuntimeService runtimeService;
 @Autowired
 private TaskService taskService;
 
 @Override
 public boolean startActivityDemo() {
 System.out.println("method startActivityDemo begin....");
  Map<String,Object> map = new HashMap<String,Object>();
  map.put("apply","zhangsan");
  map.put("approve","lisi");
//流程啟動(dòng)
  ExecutionEntity pi1 = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave",map);
  String processId = pi1.getId();
  String taskId = pi1.getTasks().get(0).getId();
  taskService.complete(taskId, map);//完成第一步申請(qǐng)
  
  Task task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
  String taskId2 = task.getId();
  map.put("pass", false);
  taskService.complete(taskId2, map);//駁回申請(qǐng)
  System.out.println("method startActivityDemo end....");
  return false;
 }
}

5.bpmn

在resources目錄下新建文件夾:processes,并在processes創(chuàng)建一個(gè)新的bpmn文件,如圖

文件內(nèi)容:

<?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" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="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/testm1510735932336" id="m1510735932336" name="">
 <process id="leave" isExecutable="true" isClosed="false" processType="None">
 <startEvent id="_2" name="StartEvent"></startEvent>
 <endEvent id="_3" name="EndEvent"></endEvent>
 <userTask id="approve" name="經(jīng)理審批" activiti:assignee="${approve}"></userTask>
 <exclusiveGateway id="_5" name="ExclusiveGateway"></exclusiveGateway>
 <sequenceFlow id="_6" sourceRef="approve" targetRef="_5"></sequenceFlow>
 <sequenceFlow id="_7" name="通過(guò)" sourceRef="_5" targetRef="_3">
  <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
 </sequenceFlow>
 <userTask id="application" name="提交申請(qǐng)" activiti:assignee="${apply}"></userTask>
 <sequenceFlow id="_9" sourceRef="_2" targetRef="application"></sequenceFlow>
 <sequenceFlow id="_10" sourceRef="application" targetRef="approve"></sequenceFlow>
 <userTask id="modify" name="修改申請(qǐng)" activiti:assignee="${apply}"></userTask>
 <sequenceFlow id="_12" name="不通過(guò)" sourceRef="_5" targetRef="modify">
  <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
 </sequenceFlow>
 <sequenceFlow id="_13" sourceRef="modify" targetRef="approve"></sequenceFlow>
 </process>
 <bpmndi:BPMNDiagram id="BPMNDiagram_leave">
 <bpmndi:BPMNPlane bpmnElement="leave" id="BPMNPlane_leave">
  <bpmndi:BPMNShape bpmnElement="_2" id="BPMNShape__2">
  <omgdc:Bounds height="35.0" width="35.0" x="15.0" y="60.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="_3" id="BPMNShape__3">
  <omgdc:Bounds height="35.0" width="35.0" x="630.0" y="63.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="approve" id="BPMNShape_approve">
  <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="50.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="_5" id="BPMNShape__5">
  <omgdc:Bounds height="40.0" width="40.0" x="505.0" y="60.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="application" id="BPMNShape_application">
  <omgdc:Bounds height="55.0" width="85.0" x="135.0" y="50.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="modify" id="BPMNShape_modify">
  <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="150.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6">
  <omgdi:waypoint x="400.0" y="77.0"></omgdi:waypoint>
  <omgdi:waypoint x="505.0" y="80.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7">
  <omgdi:waypoint x="545.0" y="80.0"></omgdi:waypoint>
  <omgdi:waypoint x="630.0" y="80.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9">
  <omgdi:waypoint x="50.0" y="77.0"></omgdi:waypoint>
  <omgdi:waypoint x="135.0" y="77.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10">
  <omgdi:waypoint x="220.0" y="77.0"></omgdi:waypoint>
  <omgdi:waypoint x="315.0" y="77.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12">
  <omgdi:waypoint x="525.0" y="100.0"></omgdi:waypoint>
  <omgdi:waypoint x="525.0" y="177.0"></omgdi:waypoint>
  <omgdi:waypoint x="400.0" y="177.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13">
  <omgdi:waypoint x="357.0" y="150.0"></omgdi:waypoint>
  <omgdi:waypoint x="357.0" y="105.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
 </bpmndi:BPMNPlane>
 </bpmndi:BPMNDiagram>
</definitions>

需要認(rèn)知的問(wèn)題:.項(xiàng)目啟動(dòng)的時(shí)候,activiti會(huì)自動(dòng)在mysql中創(chuàng)建activiti相關(guān)表,不用像oracle那樣需要手動(dòng)去創(chuàng)建

6.驗(yàn)證

啟動(dòng)項(xiàng)目前,連接數(shù)據(jù)庫(kù),查看需要連接數(shù)據(jù)庫(kù)中沒(méi)有表,啟動(dòng)項(xiàng)目完成后,刷新數(shù)據(jù)庫(kù),activiti已經(jīng)創(chuàng)建相關(guān)表,打開(kāi)act_re_procdef表,流程數(shù)據(jù)已經(jīng)存在,即流程已經(jīng)部署成功。

用瀏覽器訪問(wèn)地址:http://127.0.0.1:8081/activity/activityService/startActivityDemo

打印了預(yù)計(jì)的日志,沒(méi)有報(bào)錯(cuò)信息,查看數(shù)據(jù)庫(kù)中的act_ru_task表,發(fā)現(xiàn)剛才執(zhí)行形成的數(shù)據(jù),項(xiàng)目成功。

PS:只是簡(jiǎn)單的微服務(wù),沒(méi)有去寫(xiě)注冊(cè)服務(wù)、網(wǎng)關(guān)配置、熔斷機(jī)制等等,僅用于activiti與springboot的結(jié)合

=========================后續(xù)==========================

1.在項(xiàng)目單獨(dú)作為一個(gè)引擎,本身不部署流程的時(shí)候,如果resources目錄沒(méi)有“processes”目錄,啟動(dòng)項(xiàng)目報(bào)錯(cuò)--找不到processes目錄。需要在配置文件中添加一下內(nèi)容:

spring: 
 activiti: 
####校驗(yàn)流程文件,默認(rèn)校驗(yàn)resources下的processes文件夾里的流程文件
 check-process-definitions: false

即啟動(dòng)項(xiàng)目,不去校驗(yàn)processes。

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • SpringBoot自動(dòng)裝配原理小結(jié)

    SpringBoot自動(dòng)裝配原理小結(jié)

    Spring Boot主要作用就是簡(jiǎn)化Spring應(yīng)用的開(kāi)發(fā),開(kāi)發(fā)者只需要通過(guò)少量代碼就可以創(chuàng)建一個(gè)Spring應(yīng)用,而達(dá)到這一目的最核心的思想就是約定優(yōu)于配置。
    2021-05-05
  • springMVC如何防止表單重復(fù)提交詳解

    springMVC如何防止表單重復(fù)提交詳解

    平時(shí)開(kāi)發(fā)的項(xiàng)目中經(jīng)常會(huì)遇到表單重復(fù)提交,造成數(shù)據(jù)重復(fù),增加服務(wù)器負(fù)載,嚴(yán)重甚至?xí)斐煞?wù)器宕機(jī),因此有效防止表單重復(fù)提交有一定的必要性,這篇文章主要給大家介紹了關(guān)于springMVC如何防止表單重復(fù)提交的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • java 注解實(shí)現(xiàn)一個(gè)可配置線程池的方法示例

    java 注解實(shí)現(xiàn)一個(gè)可配置線程池的方法示例

    這篇文章主要介紹了java 注解實(shí)現(xiàn)一個(gè)可配置線程池的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • java通過(guò)方向鍵控制小球移動(dòng)的小游戲

    java通過(guò)方向鍵控制小球移動(dòng)的小游戲

    這篇文章主要為大家詳細(xì)介紹了java通過(guò)方向鍵控制小球移動(dòng)的小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Java使用FFmpeg處理視頻文件的方法教程

    Java使用FFmpeg處理視頻文件的方法教程

    這篇文章主要給大家介紹了關(guān)于Java使用FFmpeg處理視頻文件的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Java版本和C++版本的二叉樹(shù)序列化與反序列化

    Java版本和C++版本的二叉樹(shù)序列化與反序列化

    這篇文章主要介紹了Java版本和C++版本的二叉樹(shù)序列化與反序列化,二叉樹(shù)就是節(jié)點(diǎn)在內(nèi)存區(qū)域中串聯(lián)起來(lái)的,但是如果掉電,內(nèi)存上的數(shù)據(jù)就沒(méi)有了。為了保存這種結(jié)構(gòu),將二叉樹(shù)用字符串的形式保存到硬盤(pán)中,這就是序列化;從字符串形式轉(zhuǎn)換為二叉樹(shù),這就是反序列化
    2022-06-06
  • 解讀JDK1.8?默認(rèn)使用什么垃圾收集器

    解讀JDK1.8?默認(rèn)使用什么垃圾收集器

    這篇文章主要介紹了解讀JDK1.8?默認(rèn)使用什么垃圾收集器,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Spring開(kāi)發(fā)核心之AOP的實(shí)現(xiàn)與切入點(diǎn)持久化

    Spring開(kāi)發(fā)核心之AOP的實(shí)現(xiàn)與切入點(diǎn)持久化

    面向?qū)ο缶幊淌且环N編程方式,此編程方式的落地需要使用“類”和 “對(duì)象”來(lái)實(shí)現(xiàn),所以,面向?qū)ο缶幊唐鋵?shí)就是對(duì) “類”和“對(duì)象” 的使用,面向切面編程,簡(jiǎn)單的說(shuō),就是動(dòng)態(tài)地將代碼切入到類的指定方法、指定位置上的編程思想就是面向切面的編程
    2022-10-10
  • java 泛型的詳解及實(shí)例

    java 泛型的詳解及實(shí)例

    這篇文章主要介紹了java 泛型的詳解及實(shí)例的相關(guān)資料,希望通過(guò)本文大家能徹底掌握泛型的使用方法,需要的朋友可以參考下
    2017-08-08
  • Eureka源碼閱讀解析Server服務(wù)端啟動(dòng)流程實(shí)例

    Eureka源碼閱讀解析Server服務(wù)端啟動(dòng)流程實(shí)例

    這篇文章主要為大家介紹了Eureka源碼閱讀解析Server服務(wù)端啟動(dòng)流程實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10

最新評(píng)論

大悟县| 辽阳县| 山阴县| 郓城县| 栾川县| 元氏县| 马尔康县| 沙坪坝区| 唐河县| 阿克陶县| 靖西县| 香河县| 屏山县| 新余市| 靖安县| 达拉特旗| 耿马| 漳浦县| 潼南县| 崇义县| 龙里县| 昂仁县| 航空| 锡林郭勒盟| 孟连| 邵武市| 固安县| 砚山县| 咸阳市| 大厂| 贺兰县| 平陆县| 开鲁县| 静乐县| 大同市| 澳门| 饶阳县| 南和县| 疏附县| 达孜县| 怀化市|