美文网首页Q&A
spring boot和mybatis整合时报org.apach

spring boot和mybatis整合时报org.apach

作者: FFJ | 来源:发表于2018-07-23 14:08 被阅读0次

    问题:

    spring boot和mybatis整合时报:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)


    解决方法:

    出现这种错误,应该是mapper接口和对应的xml文件没有绑定,目前知道的有两种可能的原因:

    1. 在xml文件中,namespace或代表相应方法的id属性跟mapper接口没有对应
    2. 编译后,查看target中的文件,很有可能是没有生产对应的xml文件。如果是这种情况,需要在你的pom.xml的<build></build>里面添加如下代码:
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>true</filtering>
                </resource>
            </resources>
    

    补充:

    1. 在application.yml文件中需要配置mybatis.mapper-locations:,如
    mybatis:
      mapper-locations: mapper-locations: classpath*:mapper/*.xml
    

    代表mybatis需要的xml文件的路径。

    1. 在配置类上加注解@MapperScan,如
    @MapperScan("dao")
    

    代表mybatis需要的mapper接口的路径。

    相关文章

      网友评论

        本文标题:spring boot和mybatis整合时报org.apach

        本文链接:https://www.haomeiwen.com/subject/onxjmftx.html