好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Idea 解决 Could not autowire. No beans of xxxx type

IntelliJ Idea 解决 Could not autowire. No beans of ‘xxxx' type found 的错误提示

哈,在使用 @Autowired 时,今天又遇一坑,这俩波浪线是干啥子嘛:

然鹅,试了一下,控制台也不报错,可以正常运行,

数据也有:

于是,又再百度上找答案。。

问题分析

在 Idea 的 spring 工程里,经常会遇到 Could not autowire. No beans of ‘xxxx' type found 的错误提示。但程序的编译和运行都是没有问题的,这个错误提示并不会产生影响。但红色的错误提示在有些有强迫症的程序员眼里,多多少少有些不太舒服。

问题原因其一

第一个是 Intellij IDEA 本身工具的问题。

解决办法:

(1)不理它。

(2)在注解上加上:

?

1

@Autowired (required = false )

(3)降低 Autowired 检测的级别,将 Severity 的级别由之前的 error 改成 warning 或其它可以忽略的级别。

还有一个原因

这个博主没有遇到,友情粘贴!

第二个便是我们导入 @Service 包的时候导入包错误造成的。

spring auto scan 配置,在编辑情况下,无法找不到对应的bean,于是提示找不到对应 bean 的错误。常见于 mybatis 的 mapper,如下:

?

1

2

3

4

5

<!-- mapper scanner configurer -->

< bean id = "mapperScannerConfig" class = "org.mybatis.spring.mapper.MapperScannerConfigurer" >

   < property name = "basePackage" value = "com.adu.spring_test.mybatis.dao" />

   < property name = "sqlSessionFactoryBeanName" value = "sqlSessionFactory" />

</ bean >

解决办法:

?

1

错误导包 import com.alibaba.dubbo.config.annotation.Service;

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

?

1

import org.springframework.stereotype.Service;

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

原文链接:https://blog.csdn.net/qq_40147863/article/details/86103857

查看更多关于Idea 解决 Could not autowire. No beans of xxxx type的详细内容...

  阅读:11次