spring Boot 不認Mapper.xml


很久以前的筆記了,大約就是用Generatro工具自動生成代碼的時候,springboot找不到mapper.xml

之前,由於用mybatis-generator自動生成了entity,dao,mapper
但是,mapper一直不認,報錯:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.lx.ssm.dao.userDemoMapper.selectByPrimaryKey

這個錯誤是由於在application.porperties里面配置錯誤引起的,需要加上以下字段:
mybatis.mapper-locations=classpath:mapping/*.xml
////這里是告訴項目,路徑在resource文件夾下面的mapping文件夾里面,掃描mapping文件夾下面所有xml文件

同時,要在入口application.java里面注釋這個:
@MapperScan("com.lx.ssm.dao") ////這里的意思是掃描這個路徑下面的所有bean
如果沒有這個注釋,會報找不到bean錯:
Field userdao in com.lx.ssm.service.UserService required a bean of type 'com.lx.ssm.dao.userDao' that could not be found.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM