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);
}
}
运行了一下果然成功了,看来以后不能忽略警告了
版权声明:程序员胖胖胖虎阿 发表于 2022年10月4日 下午4:48。
转载请注明:SpringBoot启动项目报错: Consider defining a bean of type ‘xxx‘ in your configuration. | 胖虎的工具箱-编程导航
转载请注明:SpringBoot启动项目报错: Consider defining a bean of type ‘xxx‘ in your configuration. | 胖虎的工具箱-编程导航
相关文章
暂无评论...