SpringBoot 內(nèi)嵌 camunda的配置方法
Camunda簡介
Camunda 是一種輕量級的商業(yè)流程開源平臺。Camunda是一個基于Java的框架,支持用于工作流和流程自動化的BPMN、用于案例管理的CMMN和用于業(yè)務(wù)決策管理的DMN。
同類型的產(chǎn)品有 osworkflow、jbpm、activiti、flowable。其中:Jbpm4、Activiti、Flowable、camunda四個框架同宗同源,祖先都是Jbpm4由于jbpm、activiti、flowable這幾個流程引擎出現(xiàn)的比較早,大家對camunda流程引擎認識的不多,實際上camunda在功能上、穩(wěn)定性、性能、輕量化方面和jbpm、activiti、flowable一樣優(yōu)秀。
??https://docs.camunda.org/manual/7.21/user-guide/spring-boot-integration/
我的項目環(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
自動部署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配置類
項目中使用了多數(shù)據(jù)源,掃描不同的mapper 包,但是沒有使用
@Primary
?指定主數(shù)據(jù)源
想要 給camunda單獨指定數(shù)據(jù)源 :如果存在多個 數(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)建失敗
解決:項目中的bean和camunda的bean沖突。給項目的bean起一個別名
spring-jdbc 報錯異常
解決:可能是camunda中依賴和項目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)多個數(shù)據(jù)源或者事務(wù)管理器或者線程池
解決:項目中沒有指定主數(shù)據(jù)源,使用注解 @Primary
?
建表沒有在指定的模式下
解決:數(shù)據(jù)庫連接添加 currentSchema=camunda
?
web沒有界面,版本太低
解決:camunda-bpm-spring-boot-starter-webapp
?版本我最開始使用的是3.0.5 ,后來改用 7.17.0
web界面401
解決:項目使用了 springsecurity ,放行 /camunda/**
?
到此這篇關(guān)于SpringBoot 內(nèi)嵌 camunda的文章就介紹到這了,更多相關(guān)SpringBoot 內(nèi)嵌 camunda內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用@ConfigurationProperties注解獲取為null的解決方法
在SpringBoot中,當想需要獲取到配置文件數(shù)據(jù)時,除了可以用 Spring 自帶的@Value注解外,SpringBoot還提供了一種更加方便的方式:@ConfigurationProperties,但我們在通過通過get方法去取值一直為null,本文介紹了使用@ConfigurationProperties注解獲取為null的解決方法2024-09-09SpringBoot整合EasyCaptcha實現(xiàn)圖形驗證碼功能
這篇文章主要介紹了SpringBoot整合EasyCaptcha實現(xiàn)圖形驗證碼功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-02-02java實現(xiàn)http的Post、Get、代理訪問請求
這篇文章主要為大家提供了java實現(xiàn)http的Post、Get、代理訪問請求的相關(guān)代碼,感興趣的小伙伴們可以參考一下2016-01-01使用@TableField(updateStrategy=FieldStrategy.IGNORED)遇到的坑記錄
這篇文章主要介紹了使用@TableField(updateStrategy=FieldStrategy.IGNORED)遇到的坑及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11spring注解之@Valid和@Validated的區(qū)分總結(jié)
@Validated和@Valid在基本驗證功能上沒有太多區(qū)別,但在分組、注解地方、嵌套驗證等功能上有所不同,下面這篇文章主要給大家介紹了關(guān)于spring注解之@Valid和@Validated區(qū)分的相關(guān)資料,需要的朋友可以參考下2022-03-03解讀Spring配置與服務(wù)組件的關(guān)系和注入機制
這篇文章主要介紹了解讀Spring配置與服務(wù)組件的關(guān)系和注入機制,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-09-09