Flowable 與 bpmn.io@7.0 完整集成示例 Demo

Flowable 與 bpmn.io@7.0 完整集成示例 Demo

下面是一個完整的前后端集成示例,包含前端使用 bpmn.js 7.0 和與 Flowable 后端交互的實現。

1. 后端實現 (Spring Boot + Flowable)

1.1 添加依賴 (pom.xml)

<dependencies><!-- Spring Boot --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Flowable --><dependency><groupId>org.flowable</groupId><artifactId>flowable-spring-boot-starter</artifactId><version>6.7.0</version></dependency><!-- 其他必要依賴 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.1</version></dependency>
</dependencies>

1.2 應用配置 (application.yml)

server:port: 8080spring:datasource:url: jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1username: sapassword:driver-class-name: org.h2.Driverh2:console:enabled: truepath: /h2-consoleflowable:async-executor-activate: falsedatabase-schema-update: true

1.3 控制器 (FlowableController.java)

@RestController
@RequestMapping("/api")
public class FlowableController {@Autowiredprivate RepositoryService repositoryService;@Autowiredprivate RuntimeService runtimeService;// 部署流程@PostMapping("/deploy")public ResponseEntity<?> deployProcess(@RequestParam("file") MultipartFile file) {try {Deployment deployment = repositoryService.createDeployment().addBytes(file.getOriginalFilename(), file.getBytes()).deploy();return ResponseEntity.ok(Map.of("deploymentId", deployment.getId(),"deploymentName", deployment.getName(),"deploymentTime", deployment.getDeploymentTime()));} catch (Exception e) {return ResponseEntity.badRequest().body(e.getMessage());}}// 獲取流程定義XML@GetMapping("/process-definition/{id}/xml")public ResponseEntity<?> getProcessDefinitionXml(@PathVariable String id) {try {ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());String xml = IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8);return ResponseEntity.ok(xml);} catch (Exception e) {return ResponseEntity.badRequest().body(e.getMessage());}}// 獲取流程定義列表@GetMapping("/process-definitions")public ResponseEntity<?> getProcessDefinitions() {List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().latestVersion().list();List<Map<String, Object>> result = processDefinitions.stream().map(pd -> Map.of("id", pd.getId(),"name", pd.getName(),"key", pd.getKey(),"version", pd.getVersion(),"deploymentId", pd.getDeploymentId())).collect(Collectors.toList());return ResponseEntity.ok(result);}
}

1.4 安全配置 (SecurityConfig.java)

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.cors().and().csrf().disable().authorizeRequests().antMatchers("/api/**").authenticated().and().httpBasic();}@BeanCorsConfigurationSource corsConfigurationSource() {CorsConfiguration configuration = new CorsConfiguration();configuration.setAllowedOrigins(Arrays.asList("*"));configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));configuration.setAllowedHeaders(Arrays.asList("*"));UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();source.registerCorsConfiguration("/**", configuration);return source;}
}

2. 前端實現 (React + bpmn.js)

2.1 項目初始化

npx create-react-app flowable-bpmn-demo
cd flowable-bpmn-demo
npm install bpmn-js@7.0.0 axios

2.2 BPMN 編輯器組件 (BpmnEditor.js)

import React, { useEffect, useRef, useState } from 'react';
import BpmnModeler from 'bpmn-js/lib/Modeler';
import 'bpmn-js/dist/assets/diagram-js.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css';
import axios from 'axios';
import './BpmnEditor.css';const BpmnEditor = () => {const containerRef = useRef(null);const modelerRef = useRef(null);const [processDefinitions, setProcessDefinitions] = useState([]);const [selectedDefinition, setSelectedDefinition] = useState(null);const [xml, setXml] = useState('');// 初始化建模器useEffect(() => {if (containerRef.current && !modelerRef.current) {modelerRef.current = new BpmnModeler({container: containerRef.current,keyboard: { bindTo: document }});// 創建新流程圖createNewDiagram();}// 加載流程定義列表loadProcessDefinitions();return () => {if (modelerRef.current) {modelerRef.current.destroy();}};}, []);// 創建新流程圖const createNewDiagram = async () => {try {const result = await modelerRef.current.createDiagram();console.log('Diagram created');} catch (err) {console.error('Could not create diagram', err);}};// 加載流程定義列表const loadProcessDefinitions = async () => {try {const response = await axios.get('http://localhost:8080/api/process-definitions', {auth: {username: 'admin',password: 'test'}});setProcessDefinitions(response.data);} catch (error) {console.error('Error loading process definitions:', error);}};// 加載特定流程定義const loadProcessDefinition = async (definitionId) => {try {const response = await axios.get(`http://localhost:8080/api/process-definition/${definitionId}/xml`,{auth: {username: 'admin',password: 'test'}});await modelerRef.current.importXML(response.data);setXml(response.data);setSelectedDefinition(definitionId);} catch (error) {console.error('Error loading process definition:', error);}};// 保存當前流程圖const saveDiagram = async () => {try {const { xml } = await modelerRef.current.saveXML({ format: true });setXml(xml);const formData = new FormData();const blob = new Blob([xml], { type: 'text/xml' });formData.append('file', blob, 'process.bpmn');const response = await axios.post('http://localhost:8080/api/deploy', formData, {headers: {'Content-Type': 'multipart/form-data'},auth: {username: 'admin',password: 'test'}});alert(`Deployed successfully! Deployment ID: ${response.data.deploymentId}`);loadProcessDefinitions();} catch (error) {console.error('Error saving diagram:', error);}};return (<div className="bpmn-editor-container"><div className="toolbar"><button onClick={createNewDiagram}>New Diagram</button><button onClick={saveDiagram}>Save/Deploy</button><select value={selectedDefinition || ''}onChange={(e) => loadProcessDefinition(e.target.value)}><option value="">Load Process Definition</option>{processDefinitions.map((pd) => (<option key={pd.id} value={pd.id}>{pd.name || pd.key} (v{pd.version})</option>))}</select></div><div className="canvas" ref={containerRef}></div><div className="xml-viewer"><h3>BPMN XML</h3><textarea value={xml} onChange={(e) => setXml(e.target.value)}rows="20"/></div></div>);
};export default BpmnEditor;

2.3 樣式文件 (BpmnEditor.css)

.bpmn-editor-container {display: flex;flex-direction: column;height: 100vh;
}.toolbar {padding: 10px;background: #f5f5f5;border-bottom: 1px solid #ddd;
}.toolbar button, .toolbar select {margin-right: 10px;padding: 5px 10px;
}.canvas {flex: 1;height: 60%;border: 1px solid #ccc;
}.xml-viewer {height: 30%;padding: 10px;border-top: 1px solid #ddd;
}.xml-viewer textarea {width: 100%;height: calc(100% - 30px);font-family: monospace;
}

2.4 主應用組件 (App.js)

import React from 'react';
import './App.css';
import BpmnEditor from './BpmnEditor';function App() {return (<div className="App"><header className="App-header"><h1>Flowable + bpmn.js Integration Demo</h1></header><main><BpmnEditor /></main></div>);
}export default App;

3. 運行說明

3.1 啟動后端

  1. 啟動 Spring Boot 應用
  2. Flowable 會自動創建必要的數據庫表
  3. 后端將在 http://localhost:8080 運行

3.2 啟動前端

  1. 運行 npm start
  2. 前端將在 http://localhost:3000 運行
  3. 使用默認憑據登錄 (admin/test)

4. 功能說明

  1. 新建流程圖:創建空白的 BPMN 流程圖
  2. 保存/部署:將當前流程圖保存并部署到 Flowable
  3. 加載流程:從 Flowable 加載已部署的流程定義
  4. XML 查看/編輯:查看和編輯 BPMN XML

5. 擴展建議

  1. 添加 Flowable 特定屬性面板
  2. 集成 Flowable 表單設計器
  3. 添加流程實例啟動和監控功能
  4. 實現更完善的用戶認證和授權

這個完整示例展示了如何將 bpmn.js 7.0 與 Flowable 后端集成,實現流程建模、部署和管理的完整功能。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/76849.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/76849.shtml
英文地址,請注明出處:http://en.pswp.cn/web/76849.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ROS2 安裝詳細教程,Ubuntu 22.04.5 LTS 64 位 操作系統

一、完整安裝流程&#xff08;推薦&#xff09; 1. 安裝依賴工具 sudo apt update && sudo apt install -y software-properties-common curl gnupg2 2. 添加 ROS 2 GPG 密鑰 sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /…

STM32 基本GPIO控制

目錄 GPIO基礎知識 ?編輯IO八種工作模式 固件庫實現LED點燈 蜂鳴器 按鍵基礎知識 ?編輯繼電器 震動傳感器 433M無線模塊 GPIO基礎知識 GPIO(General-Purpose input/output,通用輸入/輸出接口) 用于感知外部信號&#xff08;輸入模式&#xff09;和控制外部設備&…

14.Chromium指紋瀏覽器開發教程之WebGL指紋定制

WebGL指紋概述 當在瀏覽器打開的網頁上瀏覽內容時&#xff0c;看到的大多是平面的、靜態的圖像和文字。但是有時想要在網頁上看到更加生動、立體的圖像&#xff0c;如3D游戲、虛擬現實應用等。這時&#xff0c;就需要用到WebGL。 簡單來說&#xff0c;WebGL&#xff08;Web G…

C# foreach 循環中獲取索引的完整方案

一、手動維護索引變量 ?實現方式?&#xff1a; 在循環外部聲明索引變量&#xff0c;每次迭代手動遞增&#xff1a; int index 0; foreach (var item in collection) { Console.WriteLine($"{index}: {item}"); index; } ?特點?&#xff1a; 簡單直接&#…

Android 下拉欄中的禁用攝像頭和麥克風隱藏

Android 下拉欄中的禁用攝像頭和麥克風隱藏 文章目錄 Android 下拉欄中的禁用攝像頭和麥克風隱藏一、前言二、下拉框中的禁用攝像頭和麥克風隱藏實現1、設置支持屬性為false2、修改代碼 三、其他1、下拉欄中的禁用攝像頭和麥克風隱藏小結2、 Android SensorPrivacyService ps&a…

數字后端設計 (四):時鐘樹綜合——讓芯片的「心跳」同步到每個角落

—— 試想全城的人要在同一秒按下開關——如果有的表快、有的表慢&#xff0c;結果會亂套&#xff01;時鐘樹綜合就是給芯片內部裝一套精準的“廣播對時系統”&#xff0c;讓所有電路踩著同一個節拍工作。 1. 為什么時鐘如此重要&#xff1f; 芯片的「心跳」&#xff1a;時鐘信…

華為網路設備學習-19 路由策略

一、 二、 注意&#xff1a; 當該節點匹配模式為permit下時&#xff0c;參考if else 當該節點匹配模式為deny下時&#xff1a; 1、該節點中的apply子語句不會執行。 2、如果滿足所有判斷&#xff08;if-match&#xff09;條件時&#xff0c;拒絕該節點并跳出&#xff08;即不…

機器學習決策樹

一、何為決策樹 決策樹&#xff08;Decision Tree&#xff09;是一種分類和回歸方法&#xff0c;是基于各種情況發生的所需條件構成決策樹&#xff0c;以實現期望最大化的一種圖解法。由于這種決策分支畫成圖形很像一棵樹的枝干&#xff0c;故稱決策樹。它的運行機制非常通俗易…

香港服務器CPU對比:Intel E3與E5系列核心區別與使用場景

香港服務器的 CPU 配置(核心數與主頻)直接決定了其并發處理能力和數據運算效率&#xff0c;例如高頻多核處理器可顯著提升多線程任務響應速度。在實際業務場景中&#xff0c;不同負載需求對 CPU 架構的要求存在顯著差異——以 Intel E3 和 E5 系列為例&#xff0c;由于兩者在性…

【Rust 精進之路之第8篇-工具賦能】深入 Cargo:依賴管理、構建配置與工作空間 (Workspace)

系列: Rust 精進之路:構建可靠、高效軟件的底層邏輯 作者: 碼覺客 發布日期: 2025-04-20 引言:超越構建,Cargo 是 Rust 生態的引擎 在我們的 Rust 學習之旅初期(第二篇),我們已經與 Cargo 有過初步的接觸。我們學會了使用 cargo new 創建項目骨架,用 cargo build 編…

#systemverilog# 進程控制問題#(八)關于#0 問題的使用(三)

今天,我們繼續研究一下上一節討論的問題。其實,還有一個小問題,我們來探討一下。 `timescale 1ns/10psmodule tb_top(); reg clk; reg reset;initial begin reset = 0; #10 reset = 1; #15 reset = 0; #50 $finish; endinitial beginfor(int i = 0; i < 4 ; i++)fork #…

Linux:簡單自定義shell

1.實現原理 考慮下?這個與shell典型的互動&#xff1a; [rootlocalhost epoll]# ls client.cpp readme.md server.cpp utility.h [rootlocalhost epoll]# ps PID TTY TIME CMD 3451 pts/0 00:00:00 bash 3514 pts/0 00:00:00 ps ?下圖的時間軸來表?事件的發?次序。其中時…

PLSQL語法入門--PL/SQL 基礎詳解

PL/SQL 基礎詳解 PL/SQL&#xff08;Procedural Language for SQL&#xff09;是 Oracle 數據庫中的一種過程式語言&#xff0c;它擴展了 SQL 的功能&#xff0c;允許開發者編寫復雜的程序邏輯。 一、匿名塊 解釋 匿名塊是 PL/SQL 的基本執行單位&#xff0c;它是一段獨立的…

Oracle--用戶管理

前言&#xff1a;本博客僅作記錄學習使用&#xff0c;部分圖片出自網絡&#xff0c;如有侵犯您的權益&#xff0c;請聯系刪除 用戶管理在 Oracle 數據庫中至關重要。一個服務器通常只運行一個 Oracle 實例&#xff0c;而一個 Oracle 用戶代表一個用戶群&#xff0c;他們通過該用…

UOS+N 卡 + CUDA 環境下 X86 架構 DeepSeek 基于 vLLM 部署與 Dify 平臺搭建指南

一、文檔說明 本文檔是一份關于 DeepSeek 在X86架構下通vLLM工具部署的操作指南&#xff0c;主要面向需要在UOSN卡CUDA環境中部署DeepSeek的技術人員&#xff0c;旨在指導文檔使用者完成從 Python 環境升級、vLLM 庫安裝、模型部署到 Dify 平臺搭建的全流程操作。 二、安裝Pyt…

操作系統之shell實現(下)

&#x1f31f; 各位看官好&#xff0c;我是maomi_9526&#xff01; &#x1f30d; 種一棵樹最好是十年前&#xff0c;其次是現在&#xff01; &#x1f680; 今天來學習C語言的相關知識。 &#x1f44d; 如果覺得這篇文章有幫助&#xff0c;歡迎您一鍵三連&#xff0c;分享給更…

Spark,流量統計案例

提前創好一個文件夾分為四個類 FlowBean中的代碼內容為&#xff1a;package org.example.flow; import org.apache.hadoop.io.Writable; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; //hadoop 序列化 //三個屬性&#xff1a;手機…

下載油管視頻 - yt-dlp

文章目錄 1. yt-dlp與you-get介紹1.1 主要功能對比1.2 使用場景1.3 安裝 2. 基本命令介紹2.1 默認下載視頻2.2 指定畫質和格式規則2.3 下載播放列表2.4 備注 3. 參考資料 之前只使用you-get下載b站視頻&#xff0c;當時了解you-get也可下載油管視頻&#xff0c;但之前無此需求&…

基于javaweb的SSM+Maven教材管理系統設計與實現(源碼+文檔+部署講解)

技術范圍&#xff1a;SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、爬蟲、數據可視化、小程序、安卓app、大數據、物聯網、機器學習等設計與開發。 主要內容&#xff1a;免費功能設計、開題報告、任務書、中期檢查PPT、系統功能實現、代碼編寫、論文編寫和輔導、論文…

VS2022+QT環境配置及基本操作

參考文章 2025最新&#xff01;Visual Studio 2022 QT6.7 環境配置全攻略&#xff1a;一鍵搞定安裝與亂碼問題&#xff0c;開發效率翻倍&#xff01;&#xff08;全網最詳細教程&#xff0c;手把手教你搭建完美開發環境&#xff01;&#xff09;_vs2022 qt-CSDN博客 下載QT …