如何实现Springboot+camunda+mysql的集成

篮之新喜  金牌会员 | 2024-6-13 20:58:25 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 523|帖子 523|积分 1573

 
本文先容基于mysql数据库,如何实现camunda与springboot的集成,如何实现基于springboot运行camunda开源流程引擎。
 
一、创建springboot工程

 
利用IDEA工具,选择File->New->roject,选择Spring Initialzr

输入springboot工程基本信息,本示例命名为“camunda-demo1”, jdk版本选择8

 
在选择springboot组件的时间,需要选择Spring Web、JDBC API、MySql Driver 这三个组件。点击下一步完成即可。

二、修改maven配置

 
2.1、修改springboot版本号
 
由于camunda版本与springboot版本有匹配关系,所以需要修改springboot版本为2.4.3,
官方推荐Camunda7.1.5版本利用Spring Boot 2.4.x版本
具体配置参考camunda官方说明文档:https://docs.camunda.org/manual/7.15/user-guide/spring-boot-integration/version-compatibility/
 
Pom.xm代码片断:
 
  1.     <parent>
  2.         <groupId>org.springframework.boot</groupId>
  3.         <artifactId>spring-boot-starter-parent</artifactId>
  4.         <version>2.4.3</version>
  5.         <relativePath/>
  6.     </parent>
复制代码
 2.2、引入camunda包
由于本示例要利用camunda流程引擎、web界面、Rest服务接口,所以需要导入camunda-bpm-spring-boot-starter、camunda-bpm-spring-boot-starter-rest、camunda-bpm-spring-boot-starter-webapp这三个依赖包,如果仅仅是利用流程引擎,只需要引入camunda-bpm-spring-boot-starter就可以了。
 
完备的pom.xml文件如下:
  1.     4.0.0    <parent>
  2.         <groupId>org.springframework.boot</groupId>
  3.         <artifactId>spring-boot-starter-parent</artifactId>
  4.         <version>2.4.3</version>
  5.         <relativePath/>
  6.     </parent>    com.example    camunda-demo1    0.0.1-SNAPSHOT    camunda-demo1    Demo project for Spring Boot            1.8                            org.springframework.boot            spring-boot-starter-web                            org.springframework.boot            spring-boot-starter-jdbc                            mysql            mysql-connector-java            runtime                            org.springframework.boot            spring-boot-starter-test            test                            org.camunda.bpm.springboot            camunda-bpm-spring-boot-starter            7.15.0                            org.camunda.bpm.springboot            camunda-bpm-spring-boot-starter-rest            7.15.0                            org.camunda.bpm.springboot            camunda-bpm-spring-boot-starter-webapp            7.15.0                                                    org.springframework.boot                spring-boot-maven-plugin                        
复制代码
 
三、修改application.yaml配置

 
打开工程目次下的main\resources\application.yaml文件,如果没有该文件,手动新建一个,录入如下信息。
  1. # Find more available configuration properties on the following pages of the documentation.
  2. # https://docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/#configure-camunda-bpm-run
  3. # https://docs.camunda.org/manual/latest/user-guide/spring-boot-integration/configuration/#camunda-engine-properties
  4. camunda.bpm:
  5.   generic-properties.properties:
  6.      javaSerializationFormatEnabled: true
  7.   admin-user:
  8.     id: demo
  9.     password: demo
  10.   run:
  11. # https://docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/#cross-origin-resource-sharing
  12.     cors:
  13.       enabled: true
  14.       allowed-origins: "*"
  15. # datasource configuration is required
  16. spring.datasource:
  17.   url: jdbc:mysql://127.0.0.1:3306/camunda-715?characterEncoding=UTF-8&useUnicode=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
  18.   driver-class-name: com.mysql.cj.jdbc.Driver
  19.   username: root
  20.   password: root
  21. # By default, Spring Boot serves static content from any directories called /static or /public or /resources or
  22. # /META-INF/resources in the classpath. To prevent users from accidentally sharing files, this is disabled here by setting static locations to NULL.
  23. # https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content
  24. spring.web.resources:
  25.   static-locations: NULL
复制代码
本示例利用的是mysql数据库,数据库URL、username、 password 跟背面数据库信息生存一致。
四、创建mysql数据库

Camunda默认利用已预先配置好的H2数据库,本示例利用mysql数据库,需要提前创建mysql数据库并导入Camunda建表脚本。
为Camunda平台创建一个数据库模式,名称为camunda715

 
导入SQL脚本。执行创建全部必须的表和默认索引的SQL DDL脚本。这些脚本可以在configuration/sql/create文件夹中找到。共2个脚本,都需要导入。

导入完成后的表结构,共40张表:

 
具体配置方法参考:https://lowcode.blog.csdn.net/article/details/117564836
五、启动springboot工程

 
创建springboot工程的时间,主动天生了SpringBootApplication启动类,运行改类启动即可。
 
package com.example.demo1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CamundaDemo1Application {

    public static void main(String[] args) {
        SpringApplication.run(CamundaDemo1Application.class, args);
    }

}

 
六、登录访问camunda

 
访问:http://localhost:8080,
默认账号密码demo/demo

 
登录成功后进入camunda控制台

 
至此,完成了springboot2.4.3+camunda7.15+mysql的集成,后续的如何设计流程、如何启动流程、如何审批流程等操作,跟非springboot方式是一致的,请参考前面的文章。
https://lowcode.blog.csdn.net/article/details/117518828
https://lowcode.blog.csdn.net/article/details/118055189
体验环境:http://www.yunchengxc.com
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

篮之新喜

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表