org.springframework.beans.factory.BeanCreationException: Error creating bean with name

Spring整合mybatis过程中出现的一个问题:
报错信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource:
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for
在这里插入图片描述

按照狂神的教学视频看的spring-mybatis整合,在看完自己手动敲代码运行的时候报了上面的个错,根据报错信息反复去检查配置文件,大小写啊,文件路径啊,完整的对比了两三次还是检查不出来,然后网上各种查报错,也没查出来结果。然后又把Spring的配置去掉,单独用mybatis的配置,结果跑出来了,然后换上spring的配置,又出现了这个错误,简直崩溃。后来又去仔细的看了一下视频,发现在配置spring的sqlSessionFactory的时候配置了mapperLocationsmapperLocations,如下:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
    <property name="mapperLocations" value="classpath:com/lr/dao/*.xml"/>
</bean>

当时只知道configLocation是引用mybatis的配置文件,没大搞清楚mapperLocations是干嘛的。所以在这里配置了mapperLocations的同时又在mybatis的配置文件里配置了mappers如下:

<mappers>
    <mapper resource="com/lr/dao/UserMapper.xml"/>
</mappers>

然后这两个配置冲突了,所以导致了错误。。。
最终把mybatis的配置文件里的mapper映射删掉或者删掉spring对映射的配置就可以解决这个错误。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值