- 在用maven配置mybatis環(huán)境時(shí)出現(xiàn)此BindingExceptiony異常谋右,發(fā)現(xiàn)在classes文件下沒有mapper配置文件硬猫,應(yīng)該是maven項(xiàng)目沒有掃描到mapper包下的xml文件补箍,
在pom.xml中加入一下代碼可以解決:
<build>
<resources>
<!-- maven項(xiàng)目中src源代碼下的xml等資源文件編譯進(jìn)classes文件夾,
注意:如果沒有這個(gè)啸蜜,它會(huì)自動(dòng)搜索resources下是否有mapper.xml文件坑雅,
如果沒有就會(huì)報(bào)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目錄下的配置文件編譯進(jìn)classes文件 -->
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>