侧边栏壁纸
博主头像
阿里灰太狼博主等级

You have to believe in yourself . That's the secret of success.

  • 累计撰写 104 篇文章
  • 累计创建 50 个标签
  • 累计收到 12 条评论

目 录CONTENT

文章目录

idea 引用 @Autowired 报错 Could not autowire 的情况

阿里灰太狼
2022-02-28 / 0 评论 / 5 点赞 / 426 阅读 / 456 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-02-28,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

问题

当我们在开发时使用 @Autowired 注入时 idea 报错:
Could not autowire. No beans of ‘xxx’ type found.
但项目仍然是不受影响的,若将其更换成 @Resource 后正常,为了能让报错消失,提供以下解决方案。

方案

  1. 老版本 idea:File -> Settings -> Editor -> Inspections -> Spring -> Spring Core -> Code -> 将 Autowiring for Bean Class 的 Severity 的级别从 Error 降为 Warning,报错即可消失。
    1644982066
  2. 新版本 idea:File -> Settings -> Editor -> Inspections -> Spring -> Spring Core -> Code -> 将 Incorrect injection point autowiring in Spring bean components 的 Severity 的级别从 Error 降为 Warning,报错即可消失。
    1644982067
5

评论区