我是靠谱客的博主 朴素白云,这篇文章主要介绍记录写mybatis的代码时遇到的一些错误2,现在分享给大家,希望可以做个参考。

问题所在:通过spring.xml(spring配置文件)扫描mybatis-config.xml(mybatis配置文件),导致扫描了两遍*mapper.xml文件。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [Beans.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘class path resource [mybatis-config.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.NullPointerException

解决方法:只让其中一个文件直接扫描。删除另一个文件中扫描*mapper.xml文件的语句。或者跳过扫描mybatis-config.xml。

在这里插入图片描述

问题所在和解决:参考该博客https://blog.csdn.net/qq_43521775/article/details/109741013

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3

我的问题:使用了selectOne方法,该方法只能返回一个结果,但SQL语句实际返回的是多个结果。
解决:将selectOne方法改为selectList方法
在这里插入图片描述

问题所在:SQL语句执行的返回值和设定接收的类型不一致

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement ‘com.down.ssm.dao.DownInformationMapper.selectAll’. It’s likely that neither a Result Type nor a Result Map was specified.

解决方法:让返回值和接收类型一致。

问题所在:连接mysql的连接开太多,被拒绝访问了

java.sql.SQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: “Too many connections”

解决方法:
1.增加可使用的连接数(不好,因为有一个最大值,总会超过的)
2.减少检测回收空闲连接的时间,减少连接存活的的时间。
3.使用代码判断连接数,超过的进入等待队列,等待空闲连接释放后再执行

最后

以上就是朴素白云最近收集整理的关于记录写mybatis的代码时遇到的一些错误2的全部内容,更多相关记录写mybatis内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部