org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

spring整合mybatis, 項目啓動調用相應dao方法出現下面錯誤 :
“org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)”
網上有幾種說法:
1. mapper.xml的命名空間(namespace)是否跟mapper接口的包名一致?
我觀察我的項目是沒有這個問題.
2. 接口的方法名,與xml中的一條sql標籤的id一致
這個問題也沒有.
3. 如果項目是maven項目,編譯後,到接口所在目錄看一看,很有可能是沒有生產對應的xml文件,因爲maven默認是不編譯的
果然我查看相應目錄:
這裏寫圖片描述
只有mapper的class文件, 並沒有對應的xml文件
解決方式:
pom.xml文件中添加:

src/main/java目錄下我們可能會放mapper.xml相關文件
src/main/resources目錄下放spring/mybatis相關文件.

 <!-- 如果不添加此節點mybatis的mapper.xml文件都會被漏掉。 -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <!-- 如果沒有此節點,src/main/resources目錄下的配置文件將被忽略 -->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章