关于在整合mybatis、spring、springmvc时出现的Invalid bound statement (not found): 错误

今天在使用ssm框架进行ajax使用测试的时候,copy了教学视频的代码,程序结构如下:

sping的关于mybatis的配置语句如下:

<!-- mapper的加强————————1.配置SqlSessionFactory -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 设置数据源 -->
    <property name="dataSource" ref="dataSource" />
    <!-- 设置MyBatis核心配置文件 -->
    <property name="configLocation" value="classpath:SqlMapConfig.xml" />
</bean>
<!-- ———————————————————2.配置Mapper扫描 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 设置Mapper扫描包 -->
    <property name="basePackage" value="it.laobing.mapper" />
</bean>

这时运行项目,出现了Invalid bound statement (not found): 错误,具体错误信息如下:

 严重: Servlet.service() for servlet [SpringMvcController] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): it.laobing.mapper.CityMapper.selectCityName] with root cause

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): it.laobing.mapper.CityMapper.selectCityName

解决方式一:

通过观察,很明显的发现,Invalid bound statement (not found)没有找到的原因是mapple.xml配置文件被从mapper包中移出来了,然而MapperScannerConfigurer类扫描的包仍旧是原来的位置,这样,CityMappers.xml就无法扫描到了,程序就会报错,解决办法是,要么将CityMappers.xml放回到定义好的扫描包下,要么在SqlMapConfig.xml中,调价mappers语句,即

<mappers>
    <mapper resource="CityMappers.xml"/>
</mappers>

如此,问题就解决了 

扫描二维码关注公众号,回复: 4410143 查看本文章

解决方式二:

在pom中添加如下语句:

  1. <resources>

  2. <resource>

  3. <directory>src/main/java</directory>

  4. <includes>

  5. <include>**/*.properties</include>

  6. <include>**/*.xml</include>

  7. </includes>

  8. <filtering>false</filtering>

  9. </resource>

  10. <resource>

  11. <directory>src/main/resources</directory>

  12. <includes>

  13. <include>**/*.properties</include>

  14. <include>**/*.xml</include>

  15. </includes>

  16. <filtering>false</filtering>

  17. </resource>

  18. </resources>

猜你喜欢

转载自blog.csdn.net/zyh99whh/article/details/81909463