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

SpringBoot整合Activiti工作流框架的使用

 更新時間:2022年02月18日 10:45:46   作者:MarlonBrando1998  
本文主要介紹了SpringBoot整合Activiti工作流框架的使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Activiti 介紹

  • Activiti是一個開源的工作流引擎,它實現(xiàn)了BPMN 2.0規(guī)范,可以發(fā)布設(shè)計好的流程定義,并通過api進行流程調(diào)度。Activiti 作為一個遵從 Apache 許可的工作流和業(yè)務(wù)流程管理開源平臺,其核心是基于 Java 的超快速、超穩(wěn)定的 BPMN2.0 流程引擎,強調(diào)流程服務(wù)的可嵌入性和可擴展性,同時更加強調(diào)面向業(yè)務(wù)人員。
  • 簡單來說activiti是一個業(yè)務(wù)流程管理引擎,會沿著設(shè)計者設(shè)計好的流程,一步一步的執(zhí)行下去,直到終點。

SpringBoot 整合

配置

activiti會框架會創(chuàng)建一系列的表,所以要配置相關(guān)數(shù)據(jù)庫的信息,需要注意的是,在url中,添加了針對數(shù)據(jù)庫的條件,其中最后一條nullCatalogMeansCurrent=true非常重要,至于有什么用就不概述了,但是沒有這條語句的話就無法自動創(chuàng)建對應(yīng)的二十八張表。

server:
  port: 8014

spring:
  application:
    name: workflow
  datasource:
    name: mysqlDatasource
    url: jdbc:mysql://localhost:3306/core?useUnicode=true&nullCatalogMeansCurrent=true
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    # 監(jiān)控統(tǒng)計攔截的filters,如果啟用log4j記得添加依賴
    filters: stat,wall
  # activiti
  activiti:
    #每次應(yīng)用啟動不檢查Activiti數(shù)據(jù)表是否存在及版本號是否匹配,提升應(yīng)用啟動速度
    database-schema-update: true
    #在項目單獨作為一個引擎,本身不部署流程的時候,如果resources目錄沒有“processes”目錄,啟動項目報錯–找不到processes目錄。需要在配置文件中添加以下內(nèi)容:
    check-process-definitions: false
    process-definition-location-prefix: classpath:/processes/
    process-definition-location-suffixes:
      -**.bpmn
      -**.bpmn20.xml
    #保存歷史數(shù)據(jù)級別設(shè)置為full最高級別,便于歷史數(shù)據(jù)的追溯
    history-level: full
  # activiti 安全訪問
  security:
    basic:
      enabled: true
    user:
      name: root
      password: root

版本問題

  • 注意 SpringBootActiviti 的版本問題
  • springboot2.0不能與activiti6.0.0直接集成使用,因為activiti6.0.0出來的時候springboot2.0還沒有出來,activiti6.0.0 支持springboot1.2.6以上,2.0.0以下的版本。

使用 starter

依賴

這個版本滿足高版本的springboot,直接使用就行

<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter</artifactId>
    <version>7.1.0.M3.1</version>
</dependency>

需要注意的是,這里的依賴版本,需要對應(yīng)數(shù)據(jù)庫中act_ge_property表中schema.version版本信息,所以一般不建議在創(chuàng)建完表之后修改依賴信息

啟動項目成功后自動創(chuàng)建表

請?zhí)砑訄D片描述

需要在配置文件中加上 activiti-security的配置

 # activiti 安全訪問
  security:
    basic:
      enabled: true
    user:
      name: root
      password: root

不使用 starter

依賴

<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring</artifactId>
    <version>6.0.0</version>
</dependency>

配置代碼

@Configuration
public class ActivitiConfig {

    private static final Logger logger = LoggerFactory.getLogger(ActivitiConfig.class);


    /**
     * 配置分為以下幾步驟
     * 1. 創(chuàng)建ActivitiConfig
     * 2. 使用ActivitiConfig創(chuàng)建ProcessEngineFactoryBean
     * 3. 使用ProcessEngineFactoryBean創(chuàng)建ProcessEngine對象
     * 4. 使用ProcessEngine對象創(chuàng)建需要的服務(wù)對象
     */
    private final DataSource dataSource;

    private final PlatformTransactionManager platformTransactionManager;

    @Autowired
    public ActivitiConfig(DataSource dataSource, PlatformTransactionManager transactionManager) {
        this.dataSource = dataSource;
        platformTransactionManager = transactionManager;
    }

    /*
     * 1. 創(chuàng)建配置文件,也就是提供一些配置信息,這樣就可以自定義自己的創(chuàng)建信息了
     * 需要一些參數(shù),1. 數(shù)據(jù)源。2. 事務(wù)管理器。
     * 這里還加入了自動掃描process包下的bpmn(流程定義文件)的設(shè)置,這樣就可以省去了部署
     * */
    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration() {
        SpringProcessEngineConfiguration spec = new SpringProcessEngineConfiguration();
        spec.setDataSource(dataSource);
        spec.setTransactionManager(platformTransactionManager);
        spec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        Resource[] resources = null;
        // 啟動自動部署流程
        try {
            resources = new PathMatchingResourcePatternResolver().getResources("classpath*:processes/*.*.xml");
        } catch (IOException e) {
            logger.error("Error Occur:", e);
        }
        spec.setDeploymentResources(resources);
        return spec;
    }

    @Bean
    public ProcessEngineFactoryBean processEngine() {
        ProcessEngineFactoryBean engineFactoryBean = new ProcessEngineFactoryBean();
        engineFactoryBean.setProcessEngineConfiguration(springProcessEngineConfiguration());
        return engineFactoryBean;
    }

    @Bean
    public RepositoryService repositoryService() throws Exception {
        return Objects.requireNonNull(processEngine().getObject()).getRepositoryService();
    }

    @Bean
    public RuntimeService runtimeService() throws Exception {
        return Objects.requireNonNull(processEngine().getObject()).getRuntimeService();
    }

    @Bean
    public TaskService taskService() throws Exception {
        return Objects.requireNonNull(processEngine().getObject()).getTaskService();
    }

    @Bean
    public HistoryService historyService() throws Exception {
        return Objects.requireNonNull(processEngine().getObject()).getHistoryService();
    }
}

resources中創(chuàng)建process文件夾,文件夾的路徑和名字需要和ActivitiConfig中的配置保持一致啟動springBoot項目即可創(chuàng)建完成

使用 Activiti

Idea 安裝 Activiti BPMN visualizer 插件

編寫測試 bpmn.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/processdef">
    <process id="test" name="test" isExecutable="true">
        <startEvent id="startevent1" name="Start"></startEvent>
        <endEvent id="endevent1" name="End"></endEvent>
        <userTask id="usertask1" name="HelloWorld" activiti:assignee="goxcheer"></userTask>
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
        <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_test">
        <bpmndi:BPMNPlane bpmnElement="test" id="BPMNPlane_test">
            <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
                <omgdc:Bounds height="35.0" width="41.0" x="220.0" y="180.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
                <omgdc:Bounds height="35.0" width="35.0" x="640.0" y="180.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
                <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="170.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
                <omgdi:waypoint x="261.0" y="197.0"></omgdi:waypoint>
                <omgdi:waypoint x="390.0" y="197.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
                <omgdi:waypoint x="495.0" y="197.0"></omgdi:waypoint>
                <omgdi:waypoint x="640.0" y="197.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

編寫測試代碼

測試代碼

@RequestMapping("/test")
@RestController
public class ActivitiTestController {

    private static final Logger logger = LoggerFactory.getLogger(ActivitiTestController.class);

    @Autowired
    RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;

    @RequestMapping("/test1")
    public void test1() {
        logger.info("Start.........");
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("test");
        logger.info("流程啟動成功,流程id:{}", pi.getId());
    }


    @RequestMapping("/test2")
    public void test2() {
        String userId = "root";
        List<Task> resultTask = taskService.createTaskQuery().processDefinitionKey("test").taskCandidateOrAssigned(userId).list();
        logger.info("任務(wù)列表:{}", resultTask);
    }

}

…簡單配置到此結(jié)束

完整配置代碼見 :https://gitee.com/Marlon_Brando/onlineshop_back/tree/develop/os_workflow

到此這篇關(guān)于SpringBoot整合Activiti工作流框架的使用的文章就介紹到這了,更多相關(guān)SpringBoot Activiti工作流內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • java獲取文件編碼,jsoup獲取html純文本操作

    java獲取文件編碼,jsoup獲取html純文本操作

    這篇文章主要介紹了java獲取文件編碼,jsoup獲取html純文本操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • 基于Arrays.sort()和lambda表達式

    基于Arrays.sort()和lambda表達式

    這篇文章主要介紹了Arrays.sort()和lambda表達式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 詳解Maven settings.xml配置(指定本地倉庫、阿里云鏡像設(shè)置)

    詳解Maven settings.xml配置(指定本地倉庫、阿里云鏡像設(shè)置)

    這篇文章主要介紹了詳解Maven settings.xml配置(指定本地倉庫、阿里云鏡像設(shè)置),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • SpringBoot集成消息隊列的項目實踐

    SpringBoot集成消息隊列的項目實踐

    本文主要介紹了SpringBoot集成消息隊列的項目實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-02-02
  • springboot多文件上傳實現(xiàn)使用postman測試多文件上傳接口

    springboot多文件上傳實現(xiàn)使用postman測試多文件上傳接口

    這篇文章主要介紹了springboot多文件上傳實現(xiàn)使用postman測試多文件上傳接口,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java中數(shù)據(jù)轉(zhuǎn)換及字符串的“+”操作方法

    Java中數(shù)據(jù)轉(zhuǎn)換及字符串的“+”操作方法

    本文主要介紹了Java中的數(shù)據(jù)類型轉(zhuǎn)換,包括隱式轉(zhuǎn)換和強制轉(zhuǎn)換,隱式轉(zhuǎn)換通常用于將范圍較小的數(shù)據(jù)類型轉(zhuǎn)換為范圍較大的數(shù)據(jù)類型,而強制轉(zhuǎn)換則是將范圍較大的數(shù)據(jù)類型轉(zhuǎn)換為范圍較小的數(shù)據(jù)類型,本文介紹Java中數(shù)據(jù)轉(zhuǎn)換以及字符串的“+”操作,感興趣的朋友一起看看吧
    2024-10-10
  • 零基礎(chǔ)寫Java知乎爬蟲之將抓取的內(nèi)容存儲到本地

    零基礎(chǔ)寫Java知乎爬蟲之將抓取的內(nèi)容存儲到本地

    上一回我們說到了如何把知乎的某些內(nèi)容爬取出來,那么這一回我們就說說怎么把這些內(nèi)容存儲到本地吧。
    2014-11-11
  • Eclipse安裝Free marker插件教程

    Eclipse安裝Free marker插件教程

    這篇文章主要為大家詳細介紹了Eclipse安裝Free marker插件教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 淺談Java多線程實現(xiàn)及同步互斥通訊

    淺談Java多線程實現(xiàn)及同步互斥通訊

    下面小編就為大家?guī)硪黄獪\談Java多線程實現(xiàn)及同步互斥通訊。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Java詳解AVL樹的應(yīng)用

    Java詳解AVL樹的應(yīng)用

    AVL樹是高度平衡的二叉樹,它的特點是AVL樹中任何節(jié)點的兩個子樹的高度最大差別為1,本文主要給大家介紹了Java如何實現(xiàn)AVL樹,需要的朋友可以參考下
    2022-07-07

最新評論

烟台市| 龙山县| 嘉禾县| 望都县| 阿城市| 全南县| 永胜县| 临沂市| 紫金县| 岳阳市| 平邑县| 深水埗区| 承德市| 定边县| 德格县| 阜宁县| 泾源县| 卫辉市| 新疆| 通化市| 迭部县| 浙江省| 宜兰市| 修武县| 石屏县| 手游| 汶上县| 蓝田县| 湖口县| 临高县| 涞水县| 乐陵市| 团风县| 蒲城县| 鄂尔多斯市| 盐亭县| 木里| 长岭县| 温州市| 临潭县| 和田县|