Consider defining a bean of type ‘XXXX‘ in your configuration.

作者在学习SpringCloud时遇到支付模块启动失败,怀疑是mapper接口未注入。通过添加@ComponentScan注解解决了问题,引发对视频内容完整性的疑问。
摘要由CSDN通过智能技术生成

今天学习尚硅谷的SpringCloud时,发现支付模块无法启动,控制台输出下面的错误:

看起来可能是dao层没有被注入。

然后根据我已有的知识,我检查了注解@Mapper

@Mapper
public interface PaymentDao {
    public int create(Payment payment);
    public Payment getPaymentById(@Param("id") long id);
}

pom也添加了starter-web依赖:

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
</dependency>

然后不知道原因了,于是凭借死马当活马医的理念,试着在启动类添加了注解@ComponentScan,结果启动成功

@SpringBootApplication
@ComponentScan(basePackages = {"com.atguigu.springcloud.dao"})
public class PaymentMain8001 {
    public static void main(String[] args){

        SpringApplication.run(PaymentMain8001.class, args);
    }
}

我是跟着视频,一行代码,一行代码的照着敲的。视频里是没有写@ComponentScan的,但是视频里却能成功启动。难道我看的视频不完整?还是什么其他原因?哎,搞不懂。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值