【Camunda 一】Springboot集成Camunda使用Mysql

 说在前面

最终会做一个开源项目,实现一些中国式审批流程功能以及讲解。点击直达

感兴趣的朋友点赞收藏

一、匹配版本

基于Camunda 7.16.0 + Springboot 2.5.8

首先我们去官网找到camunda7.16对应的springboot版本。camunda官网

使用camunda流程引擎、web界面、Rest服务接口相应依赖如下:

  • 流程引擎:camunda-bpm-spring-boot-starter
  • Rest服务接口:camunda-bpm-spring-boot-starter-rest
  • web界面模块:camunda-bpm-spring-boot-starter-webapp
<dependency>
    <groupId>org.camunda.bpm.springboot</groupId>
    <artifactId>camunda-bpm-spring-boot-starter</artifactId>
    <version>7.16.0</version>
</dependency>
<dependency>
    <groupId>org.camunda.bpm.springboot</groupId>
    <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
    <version>7.16.0</version>
</dependency>
<dependency>
    <groupId>org.camunda.bpm.springboot</groupId>
    <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
    <version>7.16.0</version>
</dependency>

 相关属性配置可参考Springboot集成配置

二、相关配置

首先新建一个数据库

 再新建一个Springboot项目,引入相关的场景启动器

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>        
        <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter</artifactId>
            <version>7.16.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>

新建application.yml文件【注意修改数据库名,数据库用户名和密码等值

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/snail?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 1234
  application:
    name: snail-workflow

camunda:
  bpm:
    filter:
      create: All tasks
      #禁止自动部署resources下面的bpmn文件
    auto-deployment-enabled: false

直接启动项目后,就可以看到数据库已经生成了49张表。如果没有自动生成表,在数据库连接后加&nullCatalogMeansCurrent=true

  • ACT_RE_*:RE代表存repository。带有此前缀的表包含“静态”信息,例如流程定义和流程资源(图像、规则等)。
  • ACT_RU_*:RU代表runtime。这些是运行时表,包含流程实例、用户任务、变量、作业等的运行时数据。引擎仅在流程实例执行期间存储运行时数据,并在流程实例结束时删除记录。这使运行时表既小又快。
  • ACT_ID_*:ID代表identity。这些表包含身份信息,例如用户、组等。
  • ACT_HI_*:HI代表history。这些是包含历史数据的表,例如过去的流程实例、变量、任务等。
  • ACT_GE_*:GE代表 general一般数据,用于各种用例

本文只集成了流程引擎。

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
您好!对于在Spring Boot中集成多数据源,可以通过以下步骤来实现Camunda与Spring Boot的集成: 1. 首先,确保已经在您的Spring Boot项目中引入了Camunda依赖。可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter</artifactId> <version>7.15.0</version> </dependency> ``` 2. 接下来,您需要在application.properties或application.yml文件中配置Camunda的数据源。例如,如果您想要使用两个数据源,可以进行如下配置: ```yaml # 第一个数据源 spring.datasource.url=jdbc:mysql://localhost:3306/db1 spring.datasource.username=username1 spring.datasource.password=password1 # 第二个数据源 spring.datasource.db2.url=jdbc:mysql://localhost:3306/db2 spring.datasource.db2.username=username2 spring.datasource.db2.password=password2 # Camunda 数据源配置 camunda.bpm.database.schema-update=true camunda.bpm.database.table-prefix=camunda. ``` 3. 在您的应用程序中,您可以使用`@Configuration`注解创建多个`DataSource` bean,并将它们注入到Camunda配置中。例如: ```java @Configuration public class DataSourceConfig { @Primary @Bean(name = "dataSource1") @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource1() { return DataSourceBuilder.create().build(); } @Bean(name = "dataSource2") @ConfigurationProperties(prefix = "spring.datasource.db2") public DataSource dataSource2() { return DataSourceBuilder.create().build(); } } @Configuration public class CamundaConfig { @Autowired @Qualifier("dataSource1") private DataSource dataSource1; @Autowired @Qualifier("dataSource2") private DataSource dataSource2; @Bean public ProcessEngineConfigurationImpl processEngineConfiguration() { SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration(); config.setDataSource(dataSource1); config.setDatabaseSchemaUpdate("true"); // 其他配置项... return config; } // 其他Camunda bean的配置... } ``` 在上面的示例中,我们通过`@Qualifier`注解来指定要注入的数据源。`@Primary`注解用于指定主要的数据源。 这样,您就可以在Spring Boot中成功集成多个数据源,并使用Camunda进行流程管理和工作流引擎相关的操作。 希望以上信息对您有所帮助!如果您还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LoneWalker、

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值