1.基于k8s部署Mysql
参考:k8s部署mysql
我安装是去掉了卷挂载。安装过程可能出现磁盘容量不够,可以通过df -h查看。
镜像下载得比较慢,可以先用docker拉取镜像。
2.搭建SpringBoot项目
(1)搭建maven项目,pom.xml依赖如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<flowable.version>6.7.2</flowable.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>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
(2)配置文件 application.yaml
spring:
datasource:
password: root
username: root
url: jdbc:mysql://x.x.x.x:31090/flowable?useUnicode=true;characterEncoding=UTF-8
driver-class-name: com.mysql.cj.jdbc.Driver
(3)启动类
package gdut;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(proxyBeanMethods = false)
@ComponentScan("gdut.**")
public class FlowableApplication {
public static void main(String[] args) {
SpringApplication.run(FlowableApplication.class, args);
}
}
3.整合flowable
参考:flowable官方文档
添加flowable的spring boot依赖,版本是6.7.2。
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>${flowable.version}</version>
</dependency>
启动启动类。数据库flowable自动创建了flowable的数据库表。
4.部署流程定义
划重点:流程定义文件需要以.bpmn20.xml结尾,不然流程定义部署会不生效。
//部署流程定义
Deployment deployment = processEngine.getRepositoryService().createDeployment()
.addClasspathResource("test.bpmn20.xml")
.name("oneTaskProcess")
.deploy();
//查询流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();
System.out.println("Found process definition : " + processDefinition.getName());
System.out.println("Number of process definitions : " + repositoryService.createProcessDefinitionQuery().count());
System.out.println("Number of tasks : " + taskService.createTaskQuery().count());
//启动流程
runtimeService.startProcessInstanceByKey("oneTaskProcess");
System.out.println("Number of tasks after process start: " + taskService.createTaskQuery().count());
参考文档
(1)出现以下问题,可能是k8s卷挂载的问题,可以把卷挂载去掉。不影响mysql使用。
解决方案参考:mysqld: Can‘t read dir of ‘/etc/mysql/conf.d/‘ (Errcode: 2 - No such file or directory
(2)数据库客户端Navicat无法连接数据库
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
(3)springboot Flowable集成 Error creating bean with name ‘flowableAppEngine‘ flowableException
(4)流程定义文件必须要以.bpmn20.xml结尾