我所使用的环境 springboot+mybatis
最近遇到了Invalid bound statement (not found)这个问题,其实说到底就是Mapper文件与Dao文件没有绑定,查了网上的很多资料,文献。按照他们所说的一点点看Dao与Mapper文件名,文件夹名称,方法名称,都不行。
下面跟大家说一下我的找问题的办法:
mybatis配置文件
<mappers>
<mapper resource="你的mapper文件所在"/>
</mappers>
spring配置文件
<!-- mybatis sqlSessionFactory -->
<bean id="commonSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis配置文件"/>
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="映射的类"/>
</bean>
<bean id="commonSqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
<constructor-arg index="0" ref="commonSqlSessionFactory"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="dao文件"/>
<property name="sqlSessionFactoryBeanName" value="commonSqlSessionFactory"/>
<property name="sqlSessionTemplateBeanName" value="commonSqlSessionTemplate"/>
</bean>
检查spring配置文件有没有被扫描
重点来了:
进入到commonSqlSessionFactory中的configLocation,打上断点,如图:
进入断点一步步打到这个位置,观察变量exposedObject,如图所示:
查看sqlSessionFactory中的mappedStatements是不是你所期望扫描的mapper文件
如果不是,查看原因到底为什么会加载成别的文件
ps:我遇到的错误是mybatis的配置文件名称重复跟里面的bean名称重复。