MybatisPlus整合TDDL数据库报错分析

2020-08-21  本文已影响0人  不二不二熊
一、概要

连接阿里Tddl分布式数据库后分页查询报错

错误日志
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
Error querying database.  Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: The jdbcUrl is Null, Cannot read database type
The error may involve defaultParameterMap
The error occurred while setting parameters
Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: The jdbcUrl is Null, Cannot read database type
MP版本
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.1.tmp</version>
        </dependency>
二、思考

从报错信息很容易就能看出是因为没有读取到url配置信息,但是在新增/删除是没有问题的,说明问题不是因为配置文件。
翻看 PaginationInterceptor分页拦截器源码

源码
DbType dbType = Optional.ofNullable(this.dbType).orElse(JdbcUtils.getDbType(connection.getMetaData().getURL()));

很明显因为orElse不管optional是否存在都执行了,导致报错。目前版本升级到3.3.2发现作者已经修复了这个bug,更换称了orElseGet

这个问题github上已经有人提了issue,参考:https://github.com/baomidou/mybatis-plus/issues/2172

三、解决

版本升级3.3.2或以上版本

上一篇下一篇

猜你喜欢

热点阅读