解决IDEA中 Could not autowire. No beans of 'xxxx' type found 的错误提示

简介: 解决IDEA中 Could not autowire. No beans of 'xxxx' type found 的错误提示

前言

近段时间,转到IDEA来开发公司项目。但是经常会出现Could not autowire. No beans of ‘xxxx’ type found的错误提示。
这个错误提示并不会产生影响,程序的编译和运行都是没有问题的。
但是对于强迫症而言,红色的错误提示是不可容忍的。所以开始着手解决
image.png

解决方案

其实出现这种问题的原因基本都是IntellijIDEA本身工具的问题。解决方案主要包括:

1)不管他

表示强迫症真的是受不了

2) 修改注解

@Autowired(required = false)

3) 使用@Resource注解

@Resource

4) 修改IDEA配置

修改IDEA设置,降低Autowired检测的级别,将Severity的级别由之前的error改成warning或其它可以忽略的级别。
image.png

其他可能原因

1. 导入包的依赖异常

第二个可能的原因是我们导入@Service包的时候导入包错误造成的
错误导包

import com.alibaba.dubbo.config.annotation.Service;

正确的包应该是下面这个:

import org.springframework.stereotype.Service;

目录
相关文章
IDEA添加Swagger2:Parameter 0 of method linkDiscoverers in org. springframework hateoas.config.Hateoasconfiguration required a single bean, but 15 were found:
IDEA添加Swagger2:Parameter 0 of method linkDiscoverers in org. springframework hateoas.config.Hateoasconfiguration required a single bean, but 15 were found
|
Java Spring
2022年1月版IntelliJ Idea报错Could not autowire. No beans of ‘xxxx‘ type found的错误
2022年1月版IntelliJ Idea报错Could not autowire. No beans of ‘xxxx‘ type found的错误
IDEA lombok is undefined for the type
IDEA lombok is undefined for the type
217 0
|
Java 测试技术 开发工具
IntelliJ IDEA中执行@Test单元测试时报错Class not found: "..."终极办法
IntelliJ IDEA中执行@Test单元测试时报错Class not found: "..."终极办法
722 0
|
Java Maven
idea执行maven打包失败:java.lang.TypeNotPresentException: Type org.springframework.boot.maven.RepackageMojo
idea执行maven打包失败:java.lang.TypeNotPresentException: Type org.springframework.boot.maven.RepackageMojo
689 0
|
JSON Java 数据库连接
IDEA在写Mybatis时遇到了Could not autowire. No beans of 'xxxx' type found 的错误提示
IDEA在写Mybatis时遇到了Could not autowire. No beans of 'xxxx' type found 的错误提示
426 0
idea springboot无法自动装配Could not autowire. No beans of ‘Xxx‘ type found.
idea springboot无法自动装配Could not autowire. No beans of ‘Xxx‘ type found.
idea springboot无法自动装配Could not autowire. No beans of ‘Xxx‘ type found.
|
Python
【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( No module named ‘numpy‘ )
【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( No module named ‘numpy‘ )
1202 0
【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( No module named ‘numpy‘ )
|
Python
【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( No module named ‘threadpool‘ )
【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( No module named ‘threadpool‘ )
1614 0
【错误记录】Mac 中 IntelliJ IDEA 运行 Python 程序报错 ( No module named ‘threadpool‘ )
Kam
|
Java 数据库连接 mybatis
Idea中@Autowire提示:Could not autowire
Idea中@Autowire提示:Could not autowire
Kam
483 0