关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

本文详细解析了SpringBoot项目中出现的自动注入失败错误,具体为在com.example.service.HelloService类型bean未找到的问题。通过排查发现,原因是Mapper包未被正确扫描。解决方案是在启动类上添加@MapperScan注解,并引入mybatis-spring-boot-starter依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description:

Field helloService in com.example.demo.service.TestController required a bean of type 'com.example.service.HelloService' that could not be found.


Action:

Consider defining a bean of type 'com.example.service.HelloService' in your configuration.

这个问题就是@SpringBootApplication无法生效的问题。因为根据英文的提示是在配置中找不到一个指定自动注入类型的bean,经过多方排查得出结论:
Mapper包是没有被扫描到的,那么我们需要在启动类上面加上注解@MapperScan,这个注解是在org…下面,不是在tk…下面。引入org…包下面的@MapperScan,需要添加依赖:

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鹿的周先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值