springboot整合mybatis报错bean

   说明你的spring boot启动时的application类不在io.github.gefangshuai.app及其子包下。
   SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描的。“Application类”是指SpringBoot项目入口类。如果Application类所在的包为:io.github.gefangshuai.app,则只会扫描io.github.gefangshuai.app包及其所有子包,如果service或dao所在包不在io.github.gefangshuai.app及其子包下,则不会被扫描。
   改变这种扫描包的方式的原理很简单:用@ComponentScan注解进行指定要扫描的包以及要扫描的类。可以用以下方式测试:
   第一步:新建两个包cn.kfit ; org.kfit;
   第二步:新建两个测试类;在这里为了方便测试,我们让我们的类在启动的时候就进行执行,所以就编写两个类,实现接口CommandLineRunner,这样在启动的时候我们就可以看到打印信息了。cn.kfit.MyCommandLineRunner1  : 12345678910111213package cn.kfit;     import org.springframework.boot.CommandLineRunner;     @Configuration  publicclass MyCommandLineRunner1 implements CommandLineRunner {         @Override      publicvoid run(String... args) throws Exception {         System.out.println("MyCommandLineRunner1.run()");         }  }org.kfit.MyCommandLineRunner2  : 12345678910111213141516package org.kfit;     import org.springframework.boot.CommandLineRunner;        @Configuration  publicclass MyCommandLineRunner2 implements CommandLineRunner {         @Override      publicvoid run(String... args) throws Exception {            System.out.println("MyCommandLineRunner2.run()");         }     }
   第三步:启动类进行注解指定;在App.java类中加入如下注解:12//可以使用:basePackageClasses={},basePackages={} 
    @ComponentScan(basePackages={"cn.kfit","org.kfit"})启动时如果看到打印信息:则说明配置成功。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值