flowable mysql55 表创建失败

阅读 55

2023-07-21

Flowable MySQL55 表创建失败

Flowable 是一个开源的工作流引擎,它提供了一套丰富的工作流管理解决方案。当我们尝试使用 Flowable 连接 MySQL55 数据库时,有时会遇到表创建失败的问题。本文将详细介绍 Flowable MySQL55 表创建失败的原因和解决方案,并提供相应的代码示例。

问题描述

在使用 Flowable 连接 MySQL55 数据库时,可能会遇到以下错误信息:

org.flowable.common.engine.api.FlowableException: problem during schema creation, statement 'create table ACT_DE_DATABASECHANGELOGLOCK (ID int(11) NOT NULL, LOCKED bit(1) NOT NULL, LOCKGRANTED datetime(3), LOCKEDBY varchar(255), constraint PK_ACT_DE_DATABASECHANGELOGLOCK primary key (ID)) ENGINE=InnoDB'

这个错误提示表明在创建 ACT_DE_DATABASECHANGELOGLOCK 表时发生了问题。

原因分析

这个问题通常是由于 MySQL55 数据库不支持创建 datetime(3) 类型的字段,导致创建表失败。Flowable 默认使用了 datetime(3) 类型来存储时间信息,但 MySQL55 只支持 datetime 类型。

解决方案

为了解决这个问题,我们需要对 Flowable 的默认设置进行修改,将 datetime(3) 类型替换为 datetime 类型。

首先,我们需要创建一个自定义的 Java 类来配置 Flowable 的数据库连接信息和其他相关设置。下面是一个示例:

import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

@Configuration
public class FlowableConfig {

    @Bean
    @ConditionalOnMissingBean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) {
        SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
        configuration.setDataSource(dataSource);
        configuration.setTransactionManager(transactionManager);
        configuration.setDatabaseSchemaUpdate("true");
        configuration.setAsyncExecutorActivate(false);
        configuration.setDatabaseType("mysql");
        configuration.setDatabaseSchema("flowable");
        configuration.setUsePrefixId(true);
        configuration.setActivityFontName("宋体");
        configuration.setAnnotationFontName("宋体");
        configuration.setI18nManagerEnabled(false);
        configuration.setDatabaseSchemaUpdate("true");
        configuration.setDatabaseTablePrefix("ACT_");
        configuration.setDatabaseTablePrefixIsSchema(true);
        configuration.setDbIdentityUsed(true);
        configuration.setAsyncExecutorActivate(false);
        configuration.setJobExecutorActivate(false);
        configuration.setDatabaseSchemaUpdate("true");
        configuration.setDatabaseType("mysql");
        configuration.setDatabaseSchema("flowable");
        configuration.setUsePrefixId(true);
        configuration.setActivityFontName("宋体");
        configuration.setAnnotationFontName("宋体");
        configuration.setI18nManagerEnabled(false);
        return configuration;
    }
}

其中,dataSourcetransactionManager 分别是数据源和事务管理器的 Bean。

然后,我们需要在主配置类中引入这个自定义配置类:

@SpringBootApplication
@Import(FlowableConfig.class)
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

最后,我们需要在 application.properties 配置文件中指定数据库连接信息和相关的 Flowable 属性:

spring.datasource.url=jdbc:mysql://localhost:3306/flowable?useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=root

flowable.database-schema-update=true
flowable.database-schema=flowable
flowable.database-table-prefix=ACT_
flowable.database-table-prefix-is-schema=true
flowable.database-schema-update=true
flowable.database-type=mysql
flowable.use-prefix-id=true
flowable.activity-font-name=宋体
flowable.annotation-font-name=宋体
flowable.i18n-manager-enabled=false

这样,我们就成功地修改了 Flowable 的默认设置,使其可以在 MySQL55 数据库中正常创建表。

总结

通过对 Flowable 的默认设置进行修改,我们可以解决在 MySQL55 数据库中创建表失败的问题。在自定义的配置类中,我们将 datetime(3) 类型替换为 datetime 类型,使其与 MySQL55 数据库兼容。通过这个简单的修改,我们可以顺利地使用 Flowable 进行工作流管理。

希望本文对你理解 Flowable MySQL55 表创建失败问题有所帮助。如果你在使用 Flowable 过程中遇到其他

精彩评论(0)

0 0 举报