No qualifying bean of type ‘com.xxx.xxx.xxx‘ available

问题

在这里插入图片描述

分析

看到这种错误想到的就是包扫描开启了没有?

解决

首先注意看一下包名写错没,如果没写错看一下包扫描开启没
如果是xml查看包扫描开启了没有?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:apo="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/util
       http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--Spring 包扫描-->
    <context:component-scan base-package="com.xxx"/>
</beans>

如果是配置类,看一下扫描注解写上了没?

@Configuration //方便spring识别这是一个配置类,可以不加
@ComponentScan("com.xxx")  //包扫描
@EnableAspectJAutoProxy(proxyTargetClass = true)  //自动装载
public class SpringConfig {
}

看清楚ComponentScan注解才是扫描注解,不是Conponent,Conponent注解主要是用于标记,告诉Spring当前类需要由容器实例化bean并放入容器中。

报错信息"No qualifying bean of type 'com.xxx' available: expected at least 1 bean which qualifies as autowire candidate"表示没有符合自动装配条件的类型为'com.xxx'的bean可用。 根据报错信息中提到的入口方法"org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)",我们可以看到问题出现在AServiceImpl的构造函数中,其中的最后一个入参是String类型。 解决该问题的方式有三种: 1. 使用@Autowired注解对属性或者方法进行Bean的注入。然而,从Spring 4.0开始,不再推荐使用属性注入模式,因为它会隐藏一些可能导致代码出错的隐患。 2. 使用@RequiredArgsConstructor(onConstructor =@_(@Autowired))注解,这样默认会通过@Autowired注入Bean。 3. 使用@RequiredArgsConstructor(onConstructor_={@Lazy})注解,对Bean进行懒加载处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [No qualifying bean of typejava.lang.Long‘ available: expected at least 1 bean which qualifies as...](https://blog.csdn.net/zzztimes/article/details/124981326)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatgptT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [No qualifying bean of typejava.lang.String‘ available: expected at least 1 bean which qualifies](https://blog.csdn.net/Saintmm/article/details/125941552)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatgptT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值