解决问题:Consider defining a bean of type ‘com.xxx.mapper.xxxMapper‘ in your configuration.

错因:

               mapper层未被加载

   创建一个springboot + mybatis的项目时,于是我发现在mapper层无法访问mysql数据库,也就是说springboot 无法加载到我们的mapper层!

 

解决问题:Consider defining a bean of type ‘com.xxx.mapper.xxxMapper‘ in your configuration._第1张图片

有2种解决方案:

               1.在你的mapper层打上mapper注解     

               2.在你的主程序打上ComponentScan注解并指定文件夹 

 1.在你的mapper层打上mapper注解     

解决问题:Consider defining a bean of type ‘com.xxx.mapper.xxxMapper‘ in your configuration._第2张图片

 2.在你的主程序打上ComponentScan注解并指定文件夹

解决问题:Consider defining a bean of type ‘com.xxx.mapper.xxxMapper‘ in your configuration._第3张图片

注意:若使用的springboot开发的多模块项目前后端分离项目即第二种不可用,因为分出很多模块,springboot找不到其他模块下的mapper层,则使用第一种方案最佳!

你可能感兴趣的:(异常,SpringBoot,Java,spring,boot,java)