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

  • 在用maven配置mybatis環境時出現此BindingExceptiony異常,發現在classes文件下沒有mapper配置文件,應該是maven項目沒有掃描到mapper包下的xml文件,
    在pom.xml中加入一下代碼可以解決:
 <build>
    <resources>  
      <!-- maven項目中src源代碼下的xml等資源文件編譯進classes文件夾,
        注意:如果沒有這個,它會自動搜索resources下是否有mapper.xml文件,
        如果沒有就會報org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey-->
      <resource>  
        <directory>src/main/java</directory>  
        <includes>  
          <include>**/*.xml</include>  
        </includes>  
      </resource>  

      <!--將resources目錄下的配置文件編譯進classes文件  -->  
      <resource>
            <directory>src/main/resources</directory>
      </resource>
    </resources>  
  </build>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章