Camunda 7.16 与 Spring Boot 3.x 集成实战:5分钟完成流程引擎嵌入与 REST API 调用
Camunda 7.16 与 Spring Boot 3.x 集成实战5分钟完成流程引擎嵌入与 REST API 调用在当今企业级应用开发中业务流程自动化已成为提升效率的关键。Camunda作为一款轻量级、高性能的开源工作流引擎与Spring Boot的完美结合能够为开发者提供快速实现复杂业务流程的能力。本文将带您从零开始在Spring Boot 3.x项目中集成Camunda 7.16社区版并通过REST API快速启动第一个流程实例。1. 环境准备与依赖配置首先创建一个全新的Spring Boot 3.x项目推荐使用Spring Initializrhttps://start.spring.io生成项目骨架。确保选择的Java版本为17或以上这是Spring Boot 3.x的最低要求。在pom.xml中添加Camunda的核心依赖dependencies !-- Spring Boot Starter -- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependency !-- Camunda核心依赖 -- dependency groupIdorg.camunda.bpm.springboot/groupId artifactIdcamunda-bpm-spring-boot-starter/artifactId version7.16.0/version /dependency !-- 可选REST API支持 -- dependency groupIdorg.camunda.bpm.springboot/groupId artifactIdcamunda-bpm-spring-boot-starter-rest/artifactId version7.16.0/version /dependency !-- 数据库支持以H2为例 -- dependency groupIdcom.h2database/groupId artifactIdh2/artifactId scoperuntime/scope /dependency /dependencies提示Camunda需要数据库支持来持久化流程定义和实例数据。在生产环境中建议使用MySQL、PostgreSQL等更稳定的数据库。2. 基础配置在application.yml中添加Camunda的基本配置spring: datasource: url: jdbc:h2:mem:camunda;DB_CLOSE_DELAY-1 username: sa password: driver-class-name: org.h2.Driver jpa: hibernate: ddl-auto: update camunda: bpm: admin-user: id: admin password: admin filter: create: All tasks database: schema-update: true auto-deployment-enabled: true关键配置说明配置项说明推荐值spring.datasource.url数据库连接URL根据实际数据库调整camunda.bpm.admin-user管理员账号生产环境务必修改camunda.bpm.database.schema-update自动更新数据库Schematrue(开发)/false(生产)camunda.bpm.auto-deployment-enabled自动部署流程定义true3. 部署第一个BPMN流程在src/main/resources目录下创建processes文件夹然后新建一个简单的请假流程leave-request.bpmn?xml version1.0 encodingUTF-8? bpmn:definitions xmlns:bpmnhttp://www.omg.org/spec/BPMN/20100524/MODEL xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI idDefinitions_1 targetNamespacehttp://bpmn.io/schema/bpmn bpmn:process idleaveRequest nameLeave Request Process isExecutabletrue bpmn:startEvent idStartEvent_1 bpmn:outgoingSequenceFlow_1/bpmn:outgoing /bpmn:startEvent bpmn:sequenceFlow idSequenceFlow_1 sourceRefStartEvent_1 targetRefTask_1 / bpmn:userTask idTask_1 nameSubmit Leave Request bpmn:incomingSequenceFlow_1/bpmn:incoming bpmn:outgoingSequenceFlow_2/bpmn:outgoing /bpmn:userTask bpmn:sequenceFlow idSequenceFlow_2 sourceRefTask_1 targetRefTask_2 / bpmn:userTask idTask_2 nameManager Approval bpmn:incomingSequenceFlow_2/bpmn:incoming bpmn:outgoingSequenceFlow_3/bpmn:outgoing /bpmn:userTask bpmn:sequenceFlow idSequenceFlow_3 sourceRefTask_2 targetRefEndEvent_1 / bpmn:endEvent idEndEvent_1 bpmn:incomingSequenceFlow_3/bpmn:incoming /bpmn:endEvent /bpmn:process bpmndi:BPMNDiagram idBPMNDiagram_1 !-- 省略图形布局定义 -- /bpmndi:BPMNDiagram /bpmn:definitions启动应用后Camunda会自动检测并部署processes目录下的BPMN文件。您可以通过以下URL访问Camunda的管理界面Cockpit: http://localhost:8080/camunda/app/cockpit/default/Tasklist: http://localhost:8080/camunda/app/tasklist/default/4. 通过Java API操作流程引擎创建一个服务类来封装常用的流程操作Service public class CamundaService { Autowired private RuntimeService runtimeService; Autowired private TaskService taskService; Autowired private RepositoryService repositoryService; // 启动流程实例 public String startProcess(String processDefinitionKey, MapString, Object variables) { ProcessInstance instance runtimeService.startProcessInstanceByKey(processDefinitionKey, variables); return instance.getId(); } // 查询用户任务 public ListTask getUserTasks(String assignee) { return taskService.createTaskQuery() .taskAssignee(assignee) .list(); } // 完成任务 public void completeTask(String taskId, MapString, Object variables) { taskService.complete(taskId, variables); } // 部署BPMN文件 public Deployment deployBpmnFile(String resourceName, InputStream inputStream) { return repositoryService.createDeployment() .addInputStream(resourceName, inputStream) .deploy(); } }5. 通过REST API操作流程引擎Camunda提供了完整的REST API支持。以下是使用Spring的RestTemplate调用API的示例RestController RequestMapping(/api/process) public class ProcessController { Autowired private RestTemplate restTemplate; private static final String CAMUNDA_ENGINE_URL http://localhost:8080/engine-rest; // 启动流程实例 PostMapping(/start/{processDefinitionKey}) public ResponseEntity? startProcess( PathVariable String processDefinitionKey, RequestBody MapString, Object variables) { String url CAMUNDA_ENGINE_URL /process-definition/key/ processDefinitionKey /start; MapString, Object request new HashMap(); request.put(variables, variables); return restTemplate.postForEntity(url, request, String.class); } // 查询任务 GetMapping(/tasks) public ResponseEntity? getTasks(RequestParam String assignee) { String url CAMUNDA_ENGINE_URL /task?assignee assignee; return restTemplate.getForEntity(url, String.class); } // 完成任务 PostMapping(/complete/{taskId}) public ResponseEntity? completeTask( PathVariable String taskId, RequestBody MapString, Object variables) { String url CAMUNDA_ENGINE_URL /task/ taskId /complete; MapString, Object request new HashMap(); request.put(variables, variables); return restTemplate.postForEntity(url, request, String.class); } }6. 测试与验证创建一个测试Controller来验证我们的集成RestController RequestMapping(/test) public class TestController { Autowired private CamundaService camundaService; PostMapping(/leave) public String applyLeave(RequestBody MapString, Object request) { // 启动请假流程 String processInstanceId camundaService.startProcess( leaveRequest, Map.of( employee, request.get(employee), days, request.get(days), reason, request.get(reason) ) ); return Leave process started with ID: processInstanceId; } GetMapping(/tasks/{assignee}) public ListMapString, Object getTasks(PathVariable String assignee) { return camundaService.getUserTasks(assignee).stream() .map(task - Map.of( id, task.getId(), name, task.getName(), created, task.getCreateTime() )) .collect(Collectors.toList()); } PostMapping(/complete/{taskId}) public String completeTask( PathVariable String taskId, RequestBody MapString, Object decision) { camundaService.completeTask(taskId, decision); return Task taskId completed; } }使用curl或Postman测试API# 启动请假流程 curl -X POST http://localhost:8080/test/leave \ -H Content-Type: application/json \ -d {employee:john,days:3,reason:Family event} # 查询john的任务 curl http://localhost:8080/test/tasks/john # 完成提交请假申请任务 curl -X POST http://localhost:8080/test/complete/{taskId} \ -H Content-Type: application/json \ -d {approved:true,comments:Approved}7. 高级配置与优化对于生产环境还需要考虑以下配置数据库连接池配置在application.yml中spring: datasource: hikari: maximum-pool-size: 20 minimum-idle: 5 idle-timeout: 30000 max-lifetime: 1800000 connection-timeout: 30000异步执行配置Configuration public class CamundaAsyncConfig { Bean public ProcessEnginePlugin asyncConfiguration() { return new AbstractProcessEnginePlugin() { Override public void preInit(ProcessEngineConfigurationImpl configuration) { configuration.setJobExecutorActivate(true); configuration.setJobExecutorDeploymentAware(true); } }; } }性能监控配置Configuration public class CamundaMetricsConfig { Bean public ProcessEnginePlugin metricsPlugin() { return new MetricsPlugin(); } Bean public MeterRegistry meterRegistry() { return new SimpleMeterRegistry(); } }通过以上步骤您已经成功在Spring Boot 3.x项目中集成了Camunda 7.16并实现了基本的流程管理和REST API调用。这种集成方式既保持了Spring Boot的简洁性又充分利用了Camunda强大的流程引擎能力。

相关新闻

工业负载控制:TPD2017FN与TM4C129LNCZAD的高可靠性方案

工业负载控制:TPD2017FN与TM4C129LNCZAD的高可靠性方案

1. 工业负载控制方案概述在工业自动化领域,精确控制电感和电阻负载是电机驱动、继电器控制和电力电子系统的核心需求。TPD2017FN智能高侧开关与TM4C129LNCZAD微控制器的组合,为工业环境中的感性/阻性负载提供了高可靠性的解决方案。这套方案特别适用于需…

2026/7/11 1:53:49阅读更多 →
tomcat之session过期问题及Redis session管理配置

tomcat之session过期问题及Redis session管理配置

使用版本tomat 7 一、Tomcat相关影响session管理的配置文件 1 . conf/content.xml,默认配置中Manager 注释不打开情况下&#xff0c;重启后后保留session不失效。 Manager 打开情况下&#xff0c;重启后会丢失session <!-- The contents of this file will be loaded for ea…

2026/7/11 1:53:49阅读更多 →
Ollama安全加固指南:防止本地大模型暴露与工具调用风险

Ollama安全加固指南:防止本地大模型暴露与工具调用风险

1. 这不是“下载慢”的问题&#xff0c;而是AI时代的第一道安全裂口你搜“ollama下载太慢了”&#xff0c;点开十篇教程&#xff0c;八篇在教你换国内镜像源、改D盘安装路径、用Docker拉取镜像——这本身没错&#xff0c;但当你把ollama run qwen3.5:9b敲进终端、服务成功启动、…

2026/7/11 1:53:49阅读更多 →
方法论解析:339题学习力诊断量表的五维架构与信效度体系

方法论解析:339题学习力诊断量表的五维架构与信效度体系

本文从系统架构角度拆解五维学习力理论及二元归因论创始人高建老师主导开发的339题标准化学习力诊断量表——其核心测量哲学、五项设计原则与信效度保障机制。 一、测量哲学&#xff1a;过程诊断而非结果评判 量表中有一道典型的认知任务题&#xff1a;学习智力维度要求孩子20秒…

2026/7/11 5:04:04阅读更多 →
Hermes Desktop 安装与 DeepSeek 模型配置:新手一篇跑通

Hermes Desktop 安装与 DeepSeek 模型配置:新手一篇跑通

这篇教程适合第一次安装 Hermes Agent Desktop 的朋友。本文演示从下载安装到接入 DeepSeek 模型的完整流程。 Hermes Agent Desktop 安装完成后&#xff0c;并不能直接使用。 它本质上是一个 Agent 桌面工具&#xff0c;需要先配置可用的大模型 API&#xff0c;才能正常对话和…

2026/7/11 5:04:04阅读更多 →
计算机毕业设计之基于springboot的音乐网站的设计与实现

计算机毕业设计之基于springboot的音乐网站的设计与实现

在Internet高速发展的今天&#xff0c;计算机的应用几乎完成覆盖我们生活的各个领域&#xff0c;互联网在经济&#xff0c;生活等方面有着举足轻重的地位&#xff0c;成为人们资源共享&#xff0c;信息快速传递的重要渠道。在中国&#xff0c;网上实现音乐网站的设计与实现的兴…

2026/7/11 5:04:04阅读更多 →
并网逆变器PLL锁相环PI参数整定:基于30度相位差的动态响应与稳态误差分析

并网逆变器PLL锁相环PI参数整定:基于30度相位差的动态响应与稳态误差分析

并网逆变器PLL锁相环PI参数整定&#xff1a;30度相位差下的动态响应与稳态误差深度解析在新能源发电系统与智能电网中&#xff0c;并网逆变器的锁相环&#xff08;PLL&#xff09;性能直接影响电能质量与系统稳定性。当电网电压存在初始相位偏差时&#xff08;如典型的30度工况…

2026/7/11 5:04:04阅读更多 →
Grok视频生成技术突破:真实感提升与X生态数据红利解析

Grok视频生成技术突破:真实感提升与X生态数据红利解析

在AI大模型快速发展的今天&#xff0c;视频生成的真实感已成为衡量技术成熟度的重要指标。最近xAI发布的Grok系列模型在视频生成领域展现出了令人瞩目的真实感&#xff0c;其效果甚至超越了传统提示词工程的范畴。这背后究竟隐藏着怎样的技术突破&#xff1f;本文将深入探讨Gro…

2026/7/11 5:04:04阅读更多 →
关于codex v0.144.1没有可用的终端执行工具的问题

关于codex v0.144.1没有可用的终端执行工具的问题

Codex 对于新版本 v0.144.1&#xff0c;收紧了对非 Git 目录的限制&#xff0c;现在需要先初始化 Git 仓库才能正常使用。 进入项目文件夹&#xff0c;使用 git init 命令创建 Git 仓库。使用 git status 命令检查仓库是否创建成功。 下图是 git status 成功输出 Git 仓库状态…

2026/7/11 4:59:04阅读更多 →
从GitHub安全案例解析常见漏洞与防护实践

从GitHub安全案例解析常见漏洞与防护实践

1. 项目概述&#xff1a;从GitHub Trending看安全实战 最近在GitHub Trending上看到一个项目&#xff0c;叫 skills4/skills &#xff0c;它因为一些安全漏洞案例被大家讨论。这其实是一个挺典型的场景&#xff1a;一个旨在展示或教授某种技能的仓库&#xff0c;本身却成了安…

2026/7/10 12:10:00阅读更多 →
MLT 2026启示:因果推理与概率建模驱动下一代LLM应用

MLT 2026启示:因果推理与概率建模驱动下一代LLM应用

# MLT 2026启示&#xff1a;因果推理与概率建模驱动下一代LLM应用## 一、背景与挑战&#xff1a;从“黑箱预测”到“可信推理”2026年6月&#xff0c;第7届机器学习与趋势国际会议&#xff08;MLT 2026&#xff09;将在悉尼召开。会议议程中&#xff0c;“因果与可解释机器学习…

2026/7/10 12:29:21阅读更多 →
通达OA SQL注入漏洞深度剖析:从手工注入到自动化利用与防御

通达OA SQL注入漏洞深度剖析:从手工注入到自动化利用与防御

1. 项目概述与漏洞背景最近在梳理一些历史OA系统的安全风险时&#xff0c;通达OA v11.6版本中的一个老漏洞又进入了我的视线。这个漏洞位于/general/bi_design/appcenter/report_bi.func.php文件中&#xff0c;是一个典型的SQL注入点。虽然这个漏洞的利用方式看起来并不复杂&am…

2026/7/10 4:59:05阅读更多 →
Premiere Pro 2025安装失败原因与AGSIS验证绕过指南

Premiere Pro 2025安装失败原因与AGSIS验证绕过指南

1. 为什么2025版PR安装比以往更“磨人”&#xff1f;——从弹窗警告到路径陷阱的真实处境 Premiere Pro 2025版不是简单的一次版本迭代&#xff0c;它是一道分水岭。我从去年底开始帮影视工作室、高校剪辑实验室和自由职业者部署2025环境&#xff0c;累计处理了137台设备&#…

2026/7/11 0:03:43阅读更多 →
5款实用macOS系统优化工具:让你的Mac运行更流畅更高效

5款实用macOS系统优化工具:让你的Mac运行更流畅更高效

5款实用macOS系统优化工具&#xff1a;让你的Mac运行更流畅更高效 【免费下载链接】open-source-mac-os-apps &#x1f680; Awesome list of open source applications for macOS. https://t.me/s/opensourcemacosapps 项目地址: https://gitcode.com/gh_mirrors/op/open-so…

2026/7/11 0:03:43阅读更多 →
5分钟完全掌握:ComfyUI ControlNet预处理器终极使用指南

5分钟完全掌握:ComfyUI ControlNet预处理器终极使用指南

5分钟完全掌握&#xff1a;ComfyUI ControlNet预处理器终极使用指南 【免费下载链接】comfyui_controlnet_aux ComfyUIs ControlNet Auxiliary Preprocessors 项目地址: https://gitcode.com/gh_mirrors/co/comfyui_controlnet_aux 想要让AI图像生成真正听从你的指挥吗&…

2026/7/11 0:03:43阅读更多 →
YOLOv8推理性能优化:从1.2FPS到35FPS的全链路加速实践

YOLOv8推理性能优化:从1.2FPS到35FPS的全链路加速实践

如果你在部署 YOLOv8 时&#xff0c;发现推理速度只有可怜的 1-2 FPS&#xff0c;而别人的演示视频却能跑到 30 FPS 以上&#xff0c;那么问题很可能不在模型本身&#xff0c;而在于你的整个处理链路。很多开发者拿到一个训练好的 YOLOv8 模型后&#xff0c;会直接使用官方示例…

2026/7/10 13:39:09阅读更多 →
Coze与Dify对比指南:低代码AI应用开发从入门到实战

Coze与Dify对比指南:低代码AI应用开发从入门到实战

1. 从零到一&#xff1a;为什么你需要了解 Coze 和 Dify&#xff1f;如果你对 AI 应用开发感兴趣&#xff0c;但一看到“大模型”、“智能体”、“工作流”这些词就头疼&#xff0c;觉得门槛太高&#xff0c;那这篇文章就是为你准备的。很多开发者&#xff0c;包括我自己&#…

2026/7/10 22:20:33阅读更多 →
AI生图工具怎么选?2026年6月版实测对比

AI生图工具怎么选?2026年6月版实测对比

做自媒体的朋友应该都有体会&#xff1a;配图一直是个让人头疼的问题。2026年&#xff0c;AI生图工具已经非常成熟了&#xff0c;但工具太多反而不知道怎么选。以下是截至2026年6月我对主流AI生图工具的实测对比。Midjourney V8.1&#xff1a;速度之王2026年6月11日&#xff0c…

2026/7/10 17:29:22阅读更多 →