踩坑springboot mybatis-plus在测试时用@Autowired注入报错的问题,expected at least 1 bean which qualifies as autowire

首先说问题:我的项目引入了mybatis-plus后,在测试时报错,这很显然是@Autowired没有将bean注入进来

expected at least 1 bean which qualifies as autowire candidate

找了一大上午问题,我发现springboot项目聚合mybatis-plus时,mybatis-plus官方推荐componentScan的写法是这样的,问题就出在这里!请对照上下两版代码,然后自己做出修改,试试能不能解决问题。

@ComponentScan(basePackages = {
		"com.gitee.sunchenbin.mybatis.actable.manager.*",
})
@SpringBootApplication
public class SpringMybatisPlusApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringMybatisPlusApplication.class, args);
	}

}

@ComponentScan(basePackages = {
		"com.train.spring_mybatis_plus",/*项目包根路径,这一行代码必须加,不然springboot无法扫描到bean*/
		"com.gitee.sunchenbin.mybatis.actable.manager.*",
})
@SpringBootApplication
public class SpringMybatisPlusApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringMybatisPlusApplication.class, args);
	}

}

你可能感兴趣的:(spring,boot,mybatis,java)