0. 简介
当前项目笔记来源于 工作流大合集
1. 创建项目
就是创建一个普通的maven项目
- 添加下列依赖
<dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>6.3.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
- 创建测试类
启动这个代码之后,会自动在数据库当中创建34张表
package net.lesscoding;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.junit.Test;
/**
* @author eleven
* @date 2023/12/24 20:01
* @apiNote
*/
public class EngineTest {
@Test
public void testProcessEngine() {
//
ProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
// 配置 相关数据库配置
configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver");
configuration.setJdbcPassword("dream");
configuration.setJdbcUsername("root");
configuration.setJdbcUrl("jdbc:mysql:///flowable_test?serverTimezone=UTC");
// 如果数据库没有表结构就自动创建
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
// 通过ProcessEngineConfiguration构建ProcessEngine对象
ProcessEngine processEngine = configuration.buildProcessEngine();
}
}
这个代码在mysql8.0
当中可能会出现下列错误
Caused by: java.sql.SQLSyntaxErrorException (create breakpoint : Table 'flowable_test.act_ge_property' doesn't exist
at com.mysql.cj.jdbc.exceptions.SOLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement,executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement,execute(ClientPreparedStatement,java:370) <4 internal lines>
出现这种情况只需要在mysql的连接字符串中添加上nullCatalogMeansCurrent=true,设置为只查当前连接的schema库即可
ProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
// 配置 相关数据库配置
configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver")
.setJdbcPassword("dream")
.setJdbcUsername("root")
.setJdbcUrl("jdbc:mysql:///flowable_test?serverTimezone=UTC&nullCatalogMeansCurrent=true");