admin管理员组文章数量:1794759
SpringBoot启动项目报错: Consider defining a bean of type ‘xxx‘ in your configuration.
今天遇到一个问题很奇怪,SpringBoot项目启动报错提示:
Description: Field userDAO in com.cml.service.impl.UserServiceImpl required a bean of type 'com.cml.dao.UserDAO' that could not be found. Action: Consider defining a bean of type 'com.cml.dao.UserDAO' in your configuration.我开始以为我是接口上面没有加@Mapper注解的原因 但是我看了一下却不是,而且idea提示我可以找到
左边那个绿色小图标点击一下也能进入UserDAO
后来我看了一下日志发现里面有一行警告被我给忽略了
2021-12-26 19:51:52.415 WARN 15212 — [ restartedMain] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in ‘[com.cml.app]’ package. Please check your configuration.
mybatis默认扫描的是启动类下的包,而我的启动类和DAO接口不在同一个包下
所以启动类加上@MapperScan注解改一下扫描位置就好了
@SpringBootApplication( scanBasePackages = "com.cml" ) @MapperScan( basePackages = "com.cml.dao" ) public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }运行了一下果然成功了,看来以后不能忽略警告了
本文标签: 报错项目definingSpringBootxxx
版权声明:本文标题:SpringBoot启动项目报错: Consider defining a bean of type ‘xxx‘ in your configuration. 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686554993a81329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论