一、创建springboot工程
使用idea工具,选择file->new->project,选择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
2
3
4
5
6
|
<parent>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-parent</artifactid>
<version> 2.4 . 3 </version>
<relativepath/>
</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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?xml version= "1.0" encoding= "utf-8" ?>
<project xmlns= "http://maven.apache.org/pom/4.0.0" xmlns:xsi= "http://www.w3.org/2001/xmlschema-instance"
xsi:schemalocation= "http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelversion> 4.0 . 0 </modelversion>
<parent>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-parent</artifactid>
<version> 2.4 . 3 </version>
<relativepath/> <!-- lookup parent from repository -->
</parent>
<groupid>com.example</groupid>
<artifactid>camunda-demo1</artifactid>
<version> 0.0 . 1 -snapshot</version>
<name>camunda-demo1</name>
<description>demo project for spring boot</description>
<properties>
<java.version> 1.8 </java.version>
</properties>
<dependencies>
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
</dependency>
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-jdbc</artifactid>
</dependency>
<dependency>
<groupid>mysql</groupid>
<artifactid>mysql-connector-java</artifactid>
<scope>runtime</scope>
</dependency>
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-test</artifactid>
<scope>test</scope>
</dependency>
<dependency>
<groupid>org.camunda.bpm.springboot</groupid>
<artifactid>camunda-bpm-spring-boot-starter</artifactid>
<version> 7.15 . 0 </version>
</dependency>
<dependency>
<groupid>org.camunda.bpm.springboot</groupid>
<artifactid>camunda-bpm-spring-boot-starter-rest</artifactid>
<version> 7.15 . 0 </version>
</dependency>
<dependency>
<groupid>org.camunda.bpm.springboot</groupid>
<artifactid>camunda-bpm-spring-boot-starter-webapp</artifactid>
<version> 7.15 . 0 </version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
</plugin>
</plugins>
</build>
</project>
|
三、修改application.yaml配置
打开工程目录下的main\resources\application.yaml文件,如果没有该文件,手动新建一个,录入如下信息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# find more available configuration properties on the following pages of the documentation.
# https: //docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/#configure-camunda-bpm-run
# https: //docs.camunda.org/manual/latest/user-guide/spring-boot-integration/configuration/#camunda-engine-properties
camunda.bpm:
generic-properties.properties:
javaserializationformatenabled: true
admin-user:
id: demo
password: demo
run:
# https: //docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/#cross-origin-resource-sharing
cors:
enabled: true
allowed-origins: "*"
# datasource configuration is required
spring.datasource:
url: jdbc:mysql: //127.0.0.1:3306/camunda715?characterencoding=utf-8&useunicode=true&usessl=false&zerodatetimebehavior=converttonull&servertimezone=asia/shanghai
driver- class -name: com.mysql.cj.jdbc.driver
username: root
password: root
# by default , spring boot serves static content from any directories called / static or / public or /resources or
# /meta-inf/resources in the classpath. to prevent users from accidentally sharing files, this is disabled here by setting static locations to null .
# https: //docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content
spring.web.resources:
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启动类,运行改类启动即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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
以上就是springboot整合camunda+mysql的集成实现方法的详细内容,更多关于springboot整合camunda的资料请关注服务器之家其它相关文章!
原文链接:https://blog.csdn.net/wxz258/article/details/118182939