本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

SpringBoot项目运行报错:SqlSession未注册_如何排查并解决?

网络教程 app 1℃

SpringBoot项目运行报错SqlSession未注册_如何排查并解决

spring boot 项目突然报错:sqlsession 未注册

问题描述:

用户运行的 spring boot 项目在运行过程中突然报错,错误信息如下:

creating a new sqlsessionsqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@2dbe837b] was not registered for synchronization because synchronization is not active

用户表示项目代码未修改,此前一直运行良好,也没有进行任何配置修改。

错误分析:

根据错误信息,可以发现 mybatis 在创建新的 sqlsession 时遇到问题,由于同步未启用,sqlsession 未被注册。

问题解决:

这个问题可能是由于 mybatis 配置文件中的错误导致的。用户提供了 spring boot 项目的 yml 配置文件,其中 mybatis 配置如下:

mybatis-plus: config-location: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml

经过分析,此配置中可能存在以下问题:

config-location 缺少点号:config-location 应指向 mybatis 主配置文件,一般是 mybatis-config.xml。但此配置中缺少了前导的点号,导致 mybatis 无法找到配置文件。多余的点号:mapper-locations 的配置也存在多余的点号。正确的配置应该是:mapper-locations: classpath:mybatis/mapper/*.xml。

解决方案:

用户可尝试以下解决方案:

    修改 config-location,加上前导点号:config-location: ./mybatis/mybatis-config.xml删除 mapper-locations 中多余的点号:mapper-locations: classpath:mybatis/mapper/*.xml

参考资料:

[mybatis 官方文档 – 配置](mybatis.org/mybatis-3/zh/configuration.html)

以上就是Spring Boot 项目运行报错:SqlSession 未注册,如何排查并解决?的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » SpringBoot项目运行报错:SqlSession未注册_如何排查并解决?

喜欢 (0)