使用IDEA,出现Could not autowire. No beans of XXX type found

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yhzhaohy/article/details/89945300

使用idea出现“Could not autowire. No beans of XXX type found”异常提醒,但是程序可以正常编译,执行。
在这里插入图片描述
(虽然报异常提醒,但是该Bean已正常实例化)

解决办法

1)@Autowired注解添加 required = false

@Autowired(required = false)

2)降低idea对@Autowired注解的检测级别,不推荐使用。
在这里插入图片描述

这两种办法只适用于程序可以正常执行的情况下,如果不是这种情况,还是老老实实的查找其他原因吧。
可能存在的问题是

Bean文件中,缺少 @Component注解或者@Repository注解

亦或是在使用Bean的文件中,@ComponentScan 注解缺少扫描路径 (basePackages={"com.antsix"})
@ComponentScan(basePackages={"com.antsix"})

猜你喜欢

转载自blog.csdn.net/yhzhaohy/article/details/89945300