Springboot集成Flowable启动报错class java.time.LocalDateTime cannot be cast to class java.lang.String解决

版本

Flowable 6.7.2

Mysql-connector-java 8.0.27

现象

Mysql驱动升级到8.0.27时,SpringBoot启动项目报了如下错误:

org.flowable.common.engine.api.FlowableException: Error initialising eventregistry data model
...
Caused by: java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.lang.String (java.time.LocalDateTime and java.lang.String are in module java.base of loader ‘bootstrap’)
at liquibase.changelog.StandardChangeLogHistoryService.getRanChangeSets(StandardChangeLogHistoryService.java:328)

原因

Flowable 6.7.2 默认依赖liquibase-core:3.8.9。

liquibase通过查询数据库表变更日志检查是否需要更新表结构,由于数据库驱动版本较新,返回的数据日期格式为LocalDateTime,导致不兼容报错。
liquibase.changelog.StandardChangeLogHistoryService

public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
    ...
    // 此处tmpDateExecuted 为LocalDateTime导致报错
    Object tmpDateExecuted = rs.get("DATEEXECUTED");
    Date dateExecuted = null;
    if (tmpDateExecuted instanceof Date) {
        dateExecuted = (Date)tmpDateExecuted;
    } else {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            dateExecuted = df.parse((String)tmpDateExecuted);
        } catch (ParseException var24) {
        }
    }
	...
}

解决

方案1:mysql数据库驱动版本退回到8.0.22(注意:8.0.22版本有漏洞存在,故做升级
方案2:liquibase-core依赖版本升级到4.8.0以后的版本修复此问题
liquibase.changelog.StandardChangeLogHistoryService

public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
	...
	Object tmpDateExecuted = rs.get("DATEEXECUTED");
    Date dateExecuted = null;
    if (tmpDateExecuted instanceof Date) {
        dateExecuted = (Date)tmpDateExecuted;
    } else if (tmpDateExecuted instanceof LocalDateTime) { // 增加了对LocalDateTime类型的处理
        dateExecuted = Date.from(((LocalDateTime)tmpDateExecuted).atZone(ZoneId.systemDefault()).toInstant());
    } else {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            dateExecuted = df.parse((String)tmpDateExecuted);
        } catch (ParseException var26) {
        }
    }
	...
}

到此,重新启动项目可以正常起来了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值