SpringBoot 內(nèi)嵌 camunda的配置方法
Camunda簡(jiǎn)介
Camunda 是一種輕量級(jí)的商業(yè)流程開源平臺(tái)。Camunda是一個(gè)基于Java的框架,支持用于工作流和流程自動(dòng)化的BPMN、用于案例管理的CMMN和用于業(yè)務(wù)決策管理的DMN。
同類型的產(chǎn)品有 osworkflow、jbpm、activiti、flowable。其中:Jbpm4、Activiti、Flowable、camunda四個(gè)框架同宗同源,祖先都是Jbpm4由于jbpm、activiti、flowable這幾個(gè)流程引擎出現(xiàn)的比較早,大家對(duì)camunda流程引擎認(rèn)識(shí)的不多,實(shí)際上camunda在功能上、穩(wěn)定性、性能、輕量化方面和jbpm、activiti、flowable一樣優(yōu)秀。
??https://docs.camunda.org/manual/7.21/user-guide/spring-boot-integration/
我的項(xiàng)目環(huán)境
- springboot :
2.0.4.RELEASE - ?jdk:
1.8 - ???????多數(shù)據(jù)源
- 數(shù)據(jù)庫:
postgresql?
引入依賴
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter</artifactId>
<version>7.17.0</version>
<exclusions>
<exclusion>
<artifactId>spring-jdbc</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
<version>7.17.0</version>
</dependency>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
<version>7.17.0</version>
</dependency>properties 配置
數(shù)據(jù)庫
postgresql?
- 自定義camunda數(shù)據(jù)源信息前綴:
camunda.datasource - ???????指定模式
currentSchema=camunda?
camunda.datasource.jdbc-url=jdbc:postgresql://xx.xx.xx.xx:5432/cc?currentSchema=camunda&stringtype=unspecified camunda.datasource.username= camunda.datasource.password= camunda.datasource.driverClassName=org.postgresql.Driver camunda.bpm.database.schema-update=true camunda.bpm.database.schema-name=camunda camunda.bpm.database.table-prefix=camunda. camunda.bpm.database.jdbc-batch-processing=true camunda.bpm.admin-user.id= camunda.bpm.admin-user.password= camunda.bpm.filter.create=All tasks camunda.bpm.history-level=audit
自動(dòng)部署bpmn
- resource下創(chuàng)建文件夾 META-INF
- 新建文件 processes.xml
<?xml version="1.0" encoding="UTF-8"?>
<process-application
xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process-archive>
<process-engine>default</process-engine>
<properties>
<property name="isDeleteUponUndeploy">false</property>
<property name="isScanForProcessDefinitions">true</property>
</properties>
</process-archive>
</process-application>- resource下創(chuàng)建文件夾 bpmn
里面放寫好的bpmn流程圖文件
java配置類
項(xiàng)目中使用了多數(shù)據(jù)源,掃描不同的mapper 包,但是沒有使用
@Primary?指定主數(shù)據(jù)源
想要 給camunda單獨(dú)指定數(shù)據(jù)源 :如果存在多個(gè) 數(shù)據(jù)源、事務(wù)管理器、線程池,需要使用?@Primary? 指定主
官方文檔:

源碼:

?package com.unicom.diamond.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
/**
* @author kj
*/
@Configuration
public class CamundaConfig {
@Bean("camundaBpmDataSource")
@ConfigurationProperties(prefix = "camunda.datasource")
public DataSource secondaryDataSource() {
return DataSourceBuilder.create().build();
}
@Bean("camundaBpmTransactionManager")
@DependsOn("camundaBpmDataSource")
public PlatformTransactionManager camundaTransactionManager(@Qualifier("camundaBpmDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}遇到問題
??historyService? bean創(chuàng)建失敗
解決:項(xiàng)目中的bean和camunda的bean沖突。給項(xiàng)目的bean起一個(gè)別名
spring-jdbc 報(bào)錯(cuò)異常
解決:可能是camunda中依賴和項(xiàng)目springboot沖突。
排除依賴
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter</artifactId>
<version>7.17.0</version>
<exclusions>
<exclusion>
<artifactId>spring-jdbc</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>發(fā)現(xiàn)多個(gè)數(shù)據(jù)源或者事務(wù)管理器或者線程池
解決:項(xiàng)目中沒有指定主數(shù)據(jù)源,使用注解 @Primary?
建表沒有在指定的模式下
解決:數(shù)據(jù)庫連接添加 currentSchema=camunda?
web沒有界面,版本太低
解決:camunda-bpm-spring-boot-starter-webapp?版本我最開始使用的是3.0.5 ,后來改用 7.17.0
web界面401
解決:項(xiàng)目使用了 springsecurity ,放行 /camunda/**?
到此這篇關(guān)于SpringBoot 內(nèi)嵌 camunda的文章就介紹到這了,更多相關(guān)SpringBoot 內(nèi)嵌 camunda內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
聊聊@RequestBody和Json之間的關(guān)系
這篇文章主要介紹了@RequestBody和Json之間的關(guān)系,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
MyBatis-Plus 分頁查詢以及自定義sql分頁的實(shí)現(xiàn)
這篇文章主要介紹了MyBatis-Plus 分頁查詢以及自定義sql分頁的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
為什么SpringMVC中請(qǐng)求的body不支持多次讀取
這篇文章主要介紹了為什么SpringMVC中請(qǐng)求的body不支持多次讀取,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
java遠(yuǎn)程連接調(diào)用Rabbitmq的實(shí)例代碼
本篇文章主要介紹了java遠(yuǎn)程連接調(diào)用Rabbitmq的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
springboot整合guava實(shí)現(xiàn)本地緩存的示例代碼
本文主要介紹了springboot整合guava實(shí)現(xiàn)本地緩存的示例代碼,包括三種回收方式及手動(dòng)清除方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-06-06
Spring Boot實(shí)戰(zhàn)教程之自動(dòng)配置詳解
Spring Boot的自動(dòng)配置給開發(fā)者帶來了很大的便利,當(dāng)開發(fā)人員在pom文件中添加starter依賴后,maven或者gradle會(huì)自動(dòng)下載很多jar包到classpath中。下面這篇文章主要給大家介紹了關(guān)于Spring Boot自動(dòng)配置的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-07-07

