
springBoot项目Consider defining a bean of type 'xxx' in your configuration错误的解决
我用IDEA创建一个springBoot项目,各种配置,mapper类和model类都检查了没有错,运行后控制台报错:
Field userMapper in com.ajax.service.J1902UserService required a bean of type ‘com.ajax.dao.J1902UserMapper’ that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) - Action: - Consider defining a bean of type ‘com.zym_ajax.dao.J1902UserMapper’ in your configuration.
就是说我的dao类没有注入成功,我就在网上查了一下,是项目的启动类没有Mapper扫描包的注解。
类上加注解@MapperScan指明Mapper类所在包的位置供SpringBoot扫描就好啦。
@SpringBootApplication @MapperScan("com.zym_ajax.dao") public class ZymAjaxApplication { public static void main(String[] args) { SpringApplication.run(ZymAjaxApplication.class, args); } }👁️ 阅读量:0
© 版权声明:本文《springBoot项目Consider defining a bean of type 'xxx' in your configuration错误的解决》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686552124a289825.html。