Exception encountered during context initialization - cancelling refresh attempt

博主分享了在Spring Boot项目中,遇到的Spring Dao配置与MyBatis映射文件冲突的问题。通过排查UserMapper.xml和mybatis-config.xml,发现由于两种配置加载方式不一致导致系统报错。解决办法在于调整映射文件的加载方式,以确保一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

💗wei_shuo的个人主页

💫wei_shuo的学习社区

🌐Hello World !


Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory

在这里插入图片描述

  • 默认类路径在spring-dao.xml

Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [spring-dao.xml]

  • 上下文初始化期间遇到异常 - 取消刷新尝试:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory

  • 看报错信息让我检查 com/wei/Mapper/UserMapper.xml

please check com/wei/Mapper/UserMapper.xml and file [D:\Java\Spring_Projects\Spring-10-mybatis\target\classes\com\wei\Mapper\UserMapper.xml]

总结:

得出错误出现在com/wei/Mapper/UserMapper.xml 中

检查UserMapper.xml 发现没有错误,只能去检查映射文件mybatis-config.xml 发现

  • UserMapper.xml中写了映射文件class加载方式
<mappers>
    <mapper class="com.wei.Mapper.UserMapper"/>
</mappers>
  • 而spring-dao.xml中也书写了映射文件加载方式
<property name="mapperLocations" value="classpath:com/wei/Mapper/*.xml"/>

总结:

两处的映射文件加载方式冲突了,所以系统报错信息才会说defined in class path resource [spring-dao.xml]

在这里插入图片描述
在这里插入图片描述


🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——点赞👍收藏⭐️评论📝冲冲冲🤞


在这里插入图片描述

评论 36
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wei_shuo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值